Module: StaticList::Model::ClassMethods
- Defined in:
- lib/static_list.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns all elements of the static list.
- #static_codes ⇒ Object
- #static_keys ⇒ Object
-
#static_list(list) ⇒ Object
Method to declare the static list in the static list model.
-
#static_list_code_to_sym(code) ⇒ Object
Returns the symbol associated with the code in parameter.
- #t_symbol(code) ⇒ Object
- #to_code(sym) ⇒ Object
Instance Method Details
#all ⇒ Object
Returns all elements of the static list
43 44 45 |
# File 'lib/static_list.rb', line 43 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 |
#static_codes ⇒ Object
68 69 70 |
# File 'lib/static_list.rb', line 68 def static_codes static_list_codes.map{ |e| e[0] } end |
#static_keys ⇒ Object
72 73 74 |
# File 'lib/static_list.rb', line 72 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.
48 49 50 |
# File 'lib/static_list.rb', line 48 def static_list(list) self.static_list_codes = list end |
#static_list_code_to_sym(code) ⇒ Object
Returns the symbol associated with the code in parameter.
For example : HairColor.static_list_code_to_sym(0) # => :white
56 57 58 |
# File 'lib/static_list.rb', line 56 def static_list_code_to_sym(code) static_list_codes.find { |el| el[1] == code }[0] end |
#t_symbol(code) ⇒ Object
60 61 62 |
# File 'lib/static_list.rb', line 60 def t_symbol(code) "#{self.to_s.demodulize.underscore}.#{self.static_list_code_to_sym(code)}" end |
#to_code(sym) ⇒ Object
64 65 66 |
# File 'lib/static_list.rb', line 64 def to_code(sym) static_list_codes.find { |el| el[0] == sym }[1] end |