Class: Infold::Enum

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/infold/property/enum.rb

Defined Under Namespace

Classes: EnumElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ Enum

Returns a new instance of Enum.



8
9
10
11
# File 'lib/infold/property/enum.rb', line 8

def initialize(field)
  @field = field
  @elements = []
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



5
6
7
# File 'lib/infold/property/enum.rb', line 5

def elements
  @elements
end

#fieldObject (readonly)

Returns the value of attribute field.



5
6
7
# File 'lib/infold/property/enum.rb', line 5

def field
  @field
end

Instance Method Details

#add_elements(**attrs) ⇒ Object



13
14
15
# File 'lib/infold/property/enum.rb', line 13

def add_elements(**attrs)
  (@elements << EnumElement.new(**attrs)).last
end

#has_color?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/infold/property/enum.rb', line 17

def has_color?
  elements.any? { |e| e.color.present? }
end