Class: Datasets::Dictionary
- Inherits:
-
Object
- Object
- Datasets::Dictionary
- Includes:
- Enumerable
- Defined in:
- lib/datasets/dictionary.rb
Instance Method Summary collapse
- #decode(ids) ⇒ Object
- #each(&block) ⇒ Object
- #encode(values) ⇒ Object
- #id(value) ⇒ Object
- #ids ⇒ Object
-
#initialize(values) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #size ⇒ Object (also: #length)
- #value(id) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(values) ⇒ Dictionary
Returns a new instance of Dictionary.
5 6 7 |
# File 'lib/datasets/dictionary.rb', line 5 def initialize(values) build_dictionary(values) end |
Instance Method Details
#decode(ids) ⇒ Object
40 41 42 43 44 |
# File 'lib/datasets/dictionary.rb', line 40 def decode(ids) ids.collect do |id| value(id) end end |
#each(&block) ⇒ Object
25 26 27 |
# File 'lib/datasets/dictionary.rb', line 25 def each(&block) @id_to_value.each(&block) end |
#encode(values) ⇒ Object
34 35 36 37 38 |
# File 'lib/datasets/dictionary.rb', line 34 def encode(values) values.collect do |value| id(value) end end |
#id(value) ⇒ Object
9 10 11 |
# File 'lib/datasets/dictionary.rb', line 9 def id(value) @value_to_id[value] end |
#ids ⇒ Object
17 18 19 |
# File 'lib/datasets/dictionary.rb', line 17 def ids @id_to_value.keys end |
#size ⇒ Object Also known as: length
29 30 31 |
# File 'lib/datasets/dictionary.rb', line 29 def size @id_to_value.size end |
#value(id) ⇒ Object
13 14 15 |
# File 'lib/datasets/dictionary.rb', line 13 def value(id) @id_to_value[id] end |
#values ⇒ Object
21 22 23 |
# File 'lib/datasets/dictionary.rb', line 21 def values @id_to_value.values end |