Module: SimpleEnum::Hasher
- Defined in:
- lib/simple_enum/hasher.rb
Constant Summary collapse
- DefaultHasher =
->(values) { Hash.new.tap do |enum_hash| pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index pairs.each { |name, value| enum_hash[name.to_s] = value } end }
- StringHasher =
->(values) { Hash.new.tap do |enum_hash| values.each { |name, *args| enum_hash[name.to_s] = name.to_s } end }
- HASHERS =
{ string: StringHasher }
Class Method Summary collapse
Class Method Details
.map(values, options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/simple_enum/hasher.rb', line 20 def self.map(values, = {}) mapper = .fetch(:map, SimpleEnum.builder) mapper = HASHERS[mapper] || DefaultHasher unless mapper.respond_to?(:call) mapper.call(values).freeze end |