Class: Protoform::FieldCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/protoform/field_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(field:, &block) ⇒ FieldCollection

Returns a new instance of FieldCollection.



7
8
9
10
11
# File 'lib/protoform/field_collection.rb', line 7

def initialize(field:, &block)
  @field = field
  @index = 0
  each(&block) if block
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
# File 'lib/protoform/field_collection.rb', line 13

def each
  Enumerator.new do |collection|
    values.each do |value|
      collection.yield build_field(value:)
    end
  end
end

#fieldObject



21
22
23
# File 'lib/protoform/field_collection.rb', line 21

def field
  build_field
end

#valuesObject



25
26
27
# File 'lib/protoform/field_collection.rb', line 25

def values
  Array(@field.value)
end