Class: SelectableAttrRails::Helpers::RadioButtonGroupHelper::Builder

Inherits:
AbstractSelectionBuilder show all
Defined in:
lib/selectable_attr_rails/helpers/radio_button_group_helper.rb

Instance Attribute Summary

Attributes inherited from AbstractSelectionBuilder

#entry_hash

Instance Method Summary collapse

Methods inherited from AbstractSelectionBuilder

#add_class_name, #camelize_keys, #enum_hash_array_from_class, #enum_hash_array_from_object, #tag_id, #update_options

Constructor Details

#initialize(object, object_name, method, options, template) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 5

def initialize(object, object_name, method, options, template)
  super(object, object_name, method, options, template)
  @entry_hash_array ||= enum_hash_array_from_class
end

Instance Method Details

#each(&block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 10

def each(&block)
  @entry_hash_array.each do |entry_hash|
    @entry_hash = entry_hash
    tag_value = @entry_hash[:id].to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
    @radio_button_id = "#{@object_name}_#{@method}_#{tag_value}"
    yield(self)
  end
end

#label(text = nil, options = nil) ⇒ Object



24
25
26
27
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 24

def label(text = nil, options = nil)
  @template.("label", text || @entry_hash[:name],
    update_options({:for => @radio_button_id}, options))
end

#radio_button(options = nil) ⇒ Object



19
20
21
22
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 19

def radio_button(options = nil)
  @template.radio_button(@object_name, @method, @entry_hash[:id], 
    update_options({:id => @radio_button_id}, options))
end