Class: Enumerize::Value

Inherits:
String
  • Object
show all
Includes:
Predicatable
Defined in:
lib/enumerize/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Predicatable

#respond_to_missing?

Constructor Details

#initialize(attr, name, value = nil) ⇒ Value

Returns a new instance of Value.



9
10
11
12
13
14
# File 'lib/enumerize/value.rb', line 9

def initialize(attr, name, value=nil)
  @attr  = attr
  @value = value.nil? ? name.to_s : value

  super(name.to_s)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Enumerize::Predicatable

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/enumerize/value.rb', line 7

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/enumerize/value.rb', line 20

def ==(other)
  super(other.to_s) || value == other
end

#encode_with(coder) ⇒ Object



24
25
26
# File 'lib/enumerize/value.rb', line 24

def encode_with(coder)
  coder.represent_object(self.class.superclass, @value)
end

#textObject



16
17
18
# File 'lib/enumerize/value.rb', line 16

def text
  I18n.t(i18n_keys[0], :default => i18n_keys[1..-1])
end