Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# Takes a lookup table with an id/label, and will make the id available via a symbol-ized label.
# 
# tableobject: The table object name (e.g. table name is 'account_statuses'; table object is AccountStatus)
# 
# Usage:
# @statuses = lookup_table AccountStatus
# 
# If:
# :id => 1, :label => 'Registered'
# :id => 2, :label => 'Recurring'
# :id => 3, :label => 'Closed'
# 
# Then:
# @statuses[:registered] => 1
# @statuses[:recurring] => 2
# @statuses[:closed] => 3
# 
def lookup_table(tableobject)
  collection = {}
  tableobject.all.each do | entry |
    collection.merge!({
      # Convert the string to be more symbol-like
      entry.label.underscore.split(' ').join('').camelize.downcase.intern => entry.id
    })
  end
  return collection
end