Module: Listly::BaseList

Defined in:
lib/listly/base_list.rb

Defined Under Namespace

Classes: MyListType

Instance Method Summary collapse

Instance Method Details

#all_list_items(type_prefix, item_class, list_items_hash = {}) ⇒ Object

  • creates items of the passed in item_class with the passed in type_prefix for code and name for list items



7
8
9
10
11
12
13
14
15
# File 'lib/listly/base_list.rb', line 7

def all_list_items(type_prefix, item_class, list_items_hash = {})
  list_items = []
  list_items_hash.each do |item|
    data = {}
    item.each{ |key, value| data["#{type_prefix}_#{key}"] = "#{value}" }
    list_items << Module.const_get("Listly::#{item_class}").new(data)
  end
  list_items
end

#list_item_name(all_items, code_field, name_field, list_item_code) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/listly/base_list.rb', line 17

def list_item_name(all_items, code_field, name_field, list_item_code)
  name = ''
  all_items.map do |item|
    if (item.send code_field) == list_item_code
      name = item.send name_field
    end
  end
  name
end