Class: EnumIsh::Dictionary
- Inherits:
-
Object
- Object
- EnumIsh::Dictionary
- Defined in:
- lib/enum_ish/dictionary.rb
Instance Method Summary collapse
-
#initialize(klass, enum, options = {}) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #translate_options ⇒ Object
- #translate_value(value) ⇒ Object
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, = {}) @klass = klass @enum = enum @options = @dict = cache { DictionaryLookup.new(@klass, @enum, @options).call } end |
Instance Method Details
#translate_options ⇒ Object
22 23 24 |
# File 'lib/enum_ish/dictionary.rb', line 22 def @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 |