Module: Enum

Included in:
Day
Defined in:
lib/enum.rb

Instance Method Summary collapse

Instance Method Details

#from_numeric(value_number) ⇒ Object


3
4
5
6
7
# File 'lib/enum.rb', line 3

def from_numeric(value_number)
  value = values[value_number]
  raise "Invalid #{self.name.demodulize} number #{value_number}" if value.nil?
  value
end

#to_numeric(value) ⇒ Object


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

def to_numeric(value)
  return value if value.is_a?(Numeric)
  value_index = values.find_index(value)
  raise "Invalid #{self.name.demodulize} value #{value}" if value_index.nil?
  value_index
end