Module: StaticList::Model::ClassMethods
- Defined in:
- lib/static_list.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns all elements of the static list.
-
#code_to_sym(code) ⇒ Object
Returns the symbol associated with the code in parameter.
- #static_codes ⇒ Object
- #static_keys ⇒ Object
-
#static_list(list) ⇒ Object
Method to declare the static list in the static list model.
-
#sym_to_code(sym) ⇒ Object
Returns the code associated with the symbol in parameter.
- #t_key_from_code(code) ⇒ Object
Instance Method Details
#all ⇒ Object
Returns all elements of the static list
45 46 47 |
# File 'lib/static_list.rb', line 45 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
58 59 60 |
# File 'lib/static_list.rb', line 58 def code_to_sym(code) static_list_codes.find { |el| el[1] == code }[0] end |
#static_codes ⇒ Object
74 75 76 |
# File 'lib/static_list.rb', line 74 def static_codes static_list_codes.map{ |e| e[0] } end |
#static_keys ⇒ Object
78 79 80 |
# File 'lib/static_list.rb', line 78 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.
50 51 52 |
# File 'lib/static_list.rb', line 50 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
66 67 68 |
# File 'lib/static_list.rb', line 66 def sym_to_code(sym) static_list_codes.find {|el| el[0] == sym }[1] end |
#t_key_from_code(code) ⇒ Object
70 71 72 |
# File 'lib/static_list.rb', line 70 def t_key_from_code(code) "#{self.to_s.demodulize.underscore}.#{self.code_to_sym(code)}" end |