Class: Datasets::Dictionary

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/datasets/dictionary.rb

Instance Method Summary collapse

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

#idsObject



17
18
19
# File 'lib/datasets/dictionary.rb', line 17

def ids
  @id_to_value.keys
end

#sizeObject 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

#valuesObject



21
22
23
# File 'lib/datasets/dictionary.rb', line 21

def values
  @id_to_value.values
end