Class: Incline::ConstantEnum

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

Direct Known Subclasses

BitEnum

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ConstantEnum

Returns a new instance of ConstantEnum.

Raises:

  • (ArgumentError)


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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/incline/constant_enum.rb', line 4

def name
  @name
end

#valueObject (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

Returns:

  • (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_sObject



12
13
14
# File 'lib/incline/constant_enum.rb', line 12

def to_s
  name
end