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

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

Instance Attribute Summary collapse

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.



9
10
11
12
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 9

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 Attribute Details

#entry_hashObject (readonly)

Returns the value of attribute entry_hash.



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

def entry_hash
  @entry_hash
end

#entry_hash_arrayObject (readonly)

Returns the value of attribute entry_hash_array.



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

def entry_hash_array
  @entry_hash_array
end

#radio_button_idObject

Returns the value of attribute radio_button_id.



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

def radio_button_id
  @radio_button_id
end

Instance Method Details

#each(&block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 14

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



28
29
30
31
# File 'lib/selectable_attr_rails/helpers/radio_button_group_helper.rb', line 28

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



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

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