Class: ActionView::Helpers::Tags::Label::LabelBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/helpers/tags/label.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_object, object_name, method_name, object, tag_value) ⇒ LabelBuilder

Returns a new instance of LabelBuilder.


8
9
10
11
12
13
14
# File 'lib/action_view/helpers/tags/label.rb', line 8

def initialize(template_object, object_name, method_name, object, tag_value)
  @template_object = template_object
  @object_name = object_name
  @method_name = method_name
  @object = object
  @tag_value = tag_value
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object


6
7
8
# File 'lib/action_view/helpers/tags/label.rb', line 6

def object
  @object
end

Instance Method Details

#translationObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/action_view/helpers/tags/label.rb', line 16

def translation
  method_and_value = @tag_value.present? ? "#{@method_name}.#{@tag_value}" : @method_name
  @object_name.gsub!(/\[(.*)_attributes\]\[\d+\]/, '.\1')

  if object.respond_to?(:to_model)
    key = object.model_name.i18n_key
    i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
  end

  i18n_default ||= ""
  content = I18n.t("#{@object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.label").presence

  content ||= if object && object.class.respond_to?(:human_attribute_name)
                object.class.human_attribute_name(method_and_value)
              end

  content ||= @method_name.humanize

  content
end