Class: ModsDisplay::RowFieldComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- ModsDisplay::RowFieldComponent
- Defined in:
- app/components/mods_display/row_field_component.rb
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#label_html_attributes ⇒ Object
readonly
Returns the value of attribute label_html_attributes.
-
#value_html_attributes ⇒ Object
readonly
Returns the value of attribute value_html_attributes.
Instance Method Summary collapse
- #format_value(value) ⇒ Object
-
#initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil) ⇒ RowFieldComponent
constructor
A new instance of RowFieldComponent.
- #label ⇒ Object
- #render? ⇒ Boolean
- #values ⇒ Object
Constructor Details
#initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil) ⇒ RowFieldComponent
Returns a new instance of RowFieldComponent.
7 8 9 10 11 12 13 14 15 |
# File 'app/components/mods_display/row_field_component.rb', line 7 def initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil) super @field = field @delimiter = delimiter @value_transformer = value_transformer @label_html_attributes = label_html_attributes @value_html_attributes = value_html_attributes end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
17 18 19 |
# File 'app/components/mods_display/row_field_component.rb', line 17 def delimiter @delimiter end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
17 18 19 |
# File 'app/components/mods_display/row_field_component.rb', line 17 def field @field end |
#label_html_attributes ⇒ Object (readonly)
Returns the value of attribute label_html_attributes.
17 18 19 |
# File 'app/components/mods_display/row_field_component.rb', line 17 def label_html_attributes @label_html_attributes end |
#value_html_attributes ⇒ Object (readonly)
Returns the value of attribute value_html_attributes.
17 18 19 |
# File 'app/components/mods_display/row_field_component.rb', line 17 def value_html_attributes @value_html_attributes end |
Instance Method Details
#format_value(value) ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/components/mods_display/row_field_component.rb', line 23 def format_value(value) if @value_transformer @value_transformer.call(value) else helpers.format_mods_html(value, field: field) end end |
#label ⇒ Object
39 40 41 |
# File 'app/components/mods_display/row_field_component.rb', line 39 def label field.label&.sub(/:$/, '') end |
#render? ⇒ Boolean
19 20 21 |
# File 'app/components/mods_display/row_field_component.rb', line 19 def render? field.values.any?(&:present?) end |
#values ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/components/mods_display/row_field_component.rb', line 31 def values if delimiter [safe_join(field.values.select(&:present?).map { |value| format_value(value) }, delimiter)] else field.values.select(&:present?).map { |value| format_value(value) } end end |