Files
news.gitea.happylizard.me/bin/gems/sass-embedded-1.104.1-x86_64-linux-gnu/lib/sass/value/map.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

72 lines
1.6 KiB
Ruby

# frozen_string_literal: true
module Sass
module Value
# Sass's map type.
#
# @see https://sass-lang.com/documentation/js-api/classes/sassmap/
class Map
include Value
# @param contents [Hash<Value, Value>]
def initialize(contents = {})
@contents = contents.freeze
end
# @return [Hash<Value, Value>]
attr_reader :contents
# @return [::String, nil]
def separator
contents.empty? ? nil : ','
end
# @return [::Boolean]
def ==(other)
(other.is_a?(Sass::Value::Map) && other.contents == contents) ||
(contents.empty? && other.is_a?(Sass::Value::List) && other.to_a.empty?)
end
# @param index [Numeric, Value]
# @return [List<(Value, Value)>, Value]
def at(index)
if index.is_a?(Numeric)
index = index.floor
index = to_a_length + index if index.negative?
return nil if index.negative? || index >= to_a_length
Sass::Value::List.new(contents.to_a[index], separator: ' ')
else
contents[index]
end
end
# @return [Integer]
def hash
@hash ||= contents.hash
end
# @return [Array<List<(Value, Value)>>]
def to_a
contents.map { |key, value| Sass::Value::List.new([key, value], separator: ' ') }
end
# @return [Map]
def to_map
self
end
# @return [Map]
def assert_map(_name = nil)
self
end
private
def to_a_length
contents.length
end
end
end
end