Class: EnumeratedAttr::Attribute
- Inherits:
-
Object
- Object
- EnumeratedAttr::Attribute
- Defined in:
- lib/enumerated_attr.rb
Instance Method Summary collapse
- #enumeration ⇒ Object
- #human(value) ⇒ Object
-
#initialize(klass, attribute, enumeration) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(klass, attribute, enumeration) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 9 10 |
# File 'lib/enumerated_attr.rb', line 6 def initialize(klass, attribute, enumeration) @klass = klass @attribute = attribute.to_sym @enumeration = enumeration end |
Instance Method Details
#enumeration ⇒ Object
17 18 19 20 21 |
# File 'lib/enumerated_attr.rb', line 17 def enumeration @enumeration.map do |value| [human(value), value] end end |
#human(value) ⇒ Object
12 13 14 15 |
# File 'lib/enumerated_attr.rb', line 12 def human(value) klass_name = @klass.name.underscore I18n.t :"enumerations.#{klass_name}.#{@attribute}.#{value}", :default => value.to_s.humanize end |