Class: Phlexi::Form::GroupedChoicesMapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/phlexi/form/grouped_choices_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection, group_method:, group_label_method: :to_s, label_method: nil, value_method: nil) ⇒ GroupedChoicesMapper

Returns a new instance of GroupedChoicesMapper.



8
9
10
11
12
13
14
# File 'lib/phlexi/form/grouped_choices_mapper.rb', line 8

def initialize(collection, group_method:, group_label_method: :to_s, label_method: nil, value_method: nil)
  @collection = collection
  @group_method = group_method
  @group_label_method = group_label_method
  @label_method = label_method
  @value_method = value_method
end

Instance Method Details

#eachObject



16
17
18
# File 'lib/phlexi/form/grouped_choices_mapper.rb', line 16

def each(&)
  grouped_choices.each(&)
end

#valuesArray<String>

Returns An array of all choice values.

Returns:

  • (Array<String>)

    An array of all choice values.



21
22
23
# File 'lib/phlexi/form/grouped_choices_mapper.rb', line 21

def values
  @values ||= grouped_choices.values.flat_map(&:values)
end