Class: Incline::ConstantEnum
- Inherits:
-
Object
- Object
- Incline::ConstantEnum
- Defined in:
- lib/incline/constant_enum.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ ConstantEnum
constructor
A new instance of ConstantEnum.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ ConstantEnum
Returns a new instance of ConstantEnum.
6 7 8 9 10 |
# File 'lib/incline/constant_enum.rb', line 6 def initialize(value) raise ArgumentError, 'Invalid value' unless self.class.named?(value) @value = value @name = self.class.name_for(value) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/incline/constant_enum.rb', line 4 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/incline/constant_enum.rb', line 4 def value @value end |
Class Method Details
.name_for(value) ⇒ Object
22 23 24 |
# File 'lib/incline/constant_enum.rb', line 22 def self.name_for(value) names.key(value) || '' end |
.named?(value) ⇒ Boolean
18 19 20 |
# File 'lib/incline/constant_enum.rb', line 18 def self.named?(value) !name_for(value).blank? end |
Instance Method Details
#to_s ⇒ Object
12 13 14 |
# File 'lib/incline/constant_enum.rb', line 12 def to_s name end |