Class: Effective::TableRow

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/table_row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, builder:) ⇒ TableRow

So this takes in the options for an entire form group.



11
12
13
14
15
16
17
# File 'app/models/effective/table_row.rb', line 11

def initialize(name, options, builder:)
  @builder = builder
  @template = builder.template

  @name = name
  @options = options
end

Instance Attribute Details

#builder ⇒ Object

Returns the value of attribute builder.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def builder
  @builder
end

#name ⇒ Object

Returns the value of attribute name.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def name
  @name
end

#options ⇒ Object

Returns the value of attribute options.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def options
  @options
end

#template ⇒ Object

Returns the value of attribute template.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def template
  @template
end

Instance Method Details

#content ⇒ Object

Intended for override



20
21
22
# File 'app/models/effective/table_row.rb', line 20

def content
  value
end

#label ⇒ Object

Humanized label or the label from form



32
33
34
35
36
37
# File 'app/models/effective/table_row.rb', line 32

def label
  text = options[:label] || builder.human_attribute_name(name)
  prefix = builder.options[:prefix]

  [*prefix, text].join(': ')
end

#to_html(&block) ⇒ Object

Render method



25
26
27
28
29
# File 'app/models/effective/table_row.rb', line 25

def to_html(&block)
  (:tr) do
    (:td, label) + (:td, content.presence || '-')
  end
end

#value ⇒ Object

Value from resource



40
41
42
# File 'app/models/effective/table_row.rb', line 40

def value
  options[:value] || builder.value(name)
end