Module: StaticList::Model::ClassMethods

Defined in:
lib/static_list.rb

Instance Method Summary collapse

Instance Method Details

#allObject

Returns all elements of the static list



46
47
48
# File 'lib/static_list.rb', line 46

def all
  static_list_codes.map{|x| Hashit.new(Hash[*["name", I18n.t("#{self.to_s.demodulize.underscore}.#{x.first.to_s}"), "id", x.last]])}
end

#code_to_sym(code) ⇒ Object

Returns the symbol associated with the code in parameter.

For example : HairColor.code_to_sym(0) # => :white



59
60
61
# File 'lib/static_list.rb', line 59

def code_to_sym(code)
  static_list_codes.find { |el| el[1] == code }[0]
end

#static_codesObject



75
76
77
# File 'lib/static_list.rb', line 75

def static_codes
  static_list_codes.map{ |e| e[0] }
end

#static_keysObject



79
80
81
# File 'lib/static_list.rb', line 79

def static_keys
  static_list_codes.map{ |e| e[1] }
end

#static_list(list) ⇒ Object

Method to declare the static list in the static list model.



51
52
53
# File 'lib/static_list.rb', line 51

def static_list(list)
  self.static_list_codes = list
end

#sym_to_code(sym) ⇒ Object

Returns the code associated with the symbol in parameter.

For example : HairColor.sym_to_code(:white) # => 0



67
68
69
# File 'lib/static_list.rb', line 67

def sym_to_code(sym)
  static_list_codes.find {|el| el[0] == sym }[1]
end

#t_key_from_code(code) ⇒ Object



71
72
73
# File 'lib/static_list.rb', line 71

def t_key_from_code(code)
  "#{self.to_s.demodulize.underscore}.#{self.code_to_sym(code)}"
end