Class: YiffSpace::Utils::TableBuilder::Column
- Inherits:
-
Object
- Object
- YiffSpace::Utils::TableBuilder::Column
- Defined in:
- lib/yiffspace/utils/table_builder.rb
Overview
Represents a single column in the table.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#body_attributes ⇒ Object
readonly
Returns the value of attribute body_attributes.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#header_attributes ⇒ Object
readonly
Returns the value of attribute header_attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(attribute = nil, column: nil, th: {}, td: {}, width: nil, name: nil) {|item| ... } ⇒ Column
constructor
Define a table column.
-
#value(item, row, column) ⇒ #to_s
Returns the value of the table cell.
Constructor Details
#initialize(attribute = nil, column: nil, th: {}, td: {}, width: nil, name: nil) {|item| ... } ⇒ Column
Define a table column.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/yiffspace/utils/table_builder.rb', line 40 def initialize(attribute = nil, column: nil, th: {}, td: {}, width: nil, name: nil, &block) @attribute = attribute @column = column @header_attributes = { width: width, **th } @body_attributes = td @block = block @name = name || attribute @name = @name.to_s.titleize unless @name.is_a?(String) return unless @name.present? || @column.present? if @column.present? column_class = "#{@column}-column" else column_class = "#{@name.parameterize.dasherize}-column" end @header_attributes[:class] = "#{column_class} #{@header_attributes[:class]}".strip @body_attributes[:class] = "#{column_class} #{@body_attributes[:class]}".strip end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def attribute @attribute end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def block @block end |
#body_attributes ⇒ Object (readonly)
Returns the value of attribute body_attributes.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def body_attributes @body_attributes end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def caption @caption end |
#header_attributes ⇒ Object (readonly)
Returns the value of attribute header_attributes.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def header_attributes @header_attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/yiffspace/utils/table_builder.rb', line 20 def name @name end |
Instance Method Details
#value(item, row, column) ⇒ #to_s
Returns the value of the table cell.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/yiffspace/utils/table_builder.rb', line 66 def value(item, row, column) if block.present? block.call(item, row, column, self) nil elsif attribute.is_a?(Symbol) item.send(attribute) else "" end end |