Class: EnumeratedAttr::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/enumerated_attr.rb

Instance Method Summary collapse

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

#enumerationObject



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