Module: Formotion::RowType::ItemsMapper

Included in:
OptionsRow, PickerRow
Defined in:
lib/formotion/row_type/items_mapper.rb

Instance Method Summary collapse

Instance Method Details

#item_namesObject



14
15
16
# File 'lib/formotion/row_type/items_mapper.rb', line 14

def item_names
  self.items.map { |name, value| name }
end

#item_names_hashObject



18
19
20
21
22
23
24
# File 'lib/formotion/row_type/items_mapper.rb', line 18

def item_names_hash
  hash = {}
  self.items.each do |name, value|
    hash[name] = value
  end
  hash
end

#itemsObject



4
5
6
7
8
9
10
11
12
# File 'lib/formotion/row_type/items_mapper.rb', line 4

def items
  if !row.items
    []
  elsif row.items[0].is_a?(Enumerable)
    row.items
  else
    row.items.map {|i| [i, i]}
  end
end

#name_for_value(value) ⇒ Object



38
39
40
# File 'lib/formotion/row_type/items_mapper.rb', line 38

def name_for_value(value)
  item_names_hash.invert[value].to_s
end

#name_index_of_value(value) ⇒ Object



26
27
28
# File 'lib/formotion/row_type/items_mapper.rb', line 26

def name_index_of_value(value)
  item_names.index(item_names_hash.invert[value])
end

#value_for_name(name) ⇒ Object



34
35
36
# File 'lib/formotion/row_type/items_mapper.rb', line 34

def value_for_name(name)
  item_names_hash[name]
end

#value_for_name_index(index) ⇒ Object



30
31
32
# File 'lib/formotion/row_type/items_mapper.rb', line 30

def value_for_name_index(index)
  item_names_hash[item_names[index]]
end