Class: Infold::Enum
- Inherits:
-
Object
- Object
- Infold::Enum
- Includes:
- ActiveModel::Model
- Defined in:
- lib/infold/property/enum.rb
Defined Under Namespace
Classes: EnumElement
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
- #add_elements(**attrs) ⇒ Object
- #has_color? ⇒ Boolean
-
#initialize(field) ⇒ Enum
constructor
A new instance of Enum.
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
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
5 6 7 |
# File 'lib/infold/property/enum.rb', line 5 def elements @elements end |
#field ⇒ Object (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
17 18 19 |
# File 'lib/infold/property/enum.rb', line 17 def has_color? elements.any? { |e| e.color.present? } end |