Class: EnumIsh::Dictionary

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Dictionary.



7
8
9
10
11
12
# File 'lib/enum_ish/dictionary.rb', line 7

def initialize(klass, enum, options = {})
  @klass = klass
  @enum = enum
  @options = options
  @dict = cache { DictionaryLookup.new(@klass, @enum, @options).call }
end

Instance Method Details

#translate_optionsObject



22
23
24
# File 'lib/enum_ish/dictionary.rb', line 22

def translate_options
  @dict.to_a.map { |value, text| [text, value] }
end

#translate_value(value) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/enum_ish/dictionary.rb', line 14

def translate_value(value)
  if value.is_a?(Array)
    value.map { |v| @dict[v] || v }
  else
    @dict[value] || value
  end
end