Class: NumeritajTipo::EnumType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, values) ⇒ EnumType

Returns a new instance of EnumType.



5
6
7
8
# File 'lib/numeritaj_tipo/enum_type.rb', line 5

def initialize(type, values)
  @type = type.to_s.classify.constantize
  @enum_values = @type < NumeritajTipo::EnumBase ? @type.values : values
end

Instance Attribute Details

#enum_valuesObject (readonly)

Returns the value of attribute enum_values.



3
4
5
# File 'lib/numeritaj_tipo/enum_type.rb', line 3

def enum_values
  @enum_values
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/numeritaj_tipo/enum_type.rb', line 3

def type
  @type
end

Instance Method Details

#values_for_validationObject



10
11
12
13
14
# File 'lib/numeritaj_tipo/enum_type.rb', line 10

def values_for_validation
  return enum_values unless type < NumeritajTipo::EnumBase

  enum_values.map {|value| type.build(value) }
end