Class: EnumIsh::DictionaryLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/enum_ish/dictionary_lookup.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, enum, options = {}) ⇒ DictionaryLookup

Returns a new instance of DictionaryLookup.



5
6
7
8
9
# File 'lib/enum_ish/dictionary_lookup.rb', line 5

def initialize(klass, enum, options = {})
  @klass = klass
  @enum = enum
  @options = options
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/enum_ish/dictionary_lookup.rb', line 11

def call
  i18n = lookup_for(@klass).transform_keys { |k| k.to_s.to_sym }

  dict = {}
  if @enum.use?(:accessor)
    @enum.mapping.each { |k, v| dict[k] = i18n[k] }
  else
    @enum.mapping.each { |k, v| dict[v] = i18n[k] }
  end

  filter(dict)
end