Class: Tableficate::Column
- Inherits:
-
Object
- Object
- Tableficate::Column
- Defined in:
- lib/tableficate/column.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#cell_attrs ⇒ Object
readonly
Returns the value of attribute cell_attrs.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#header_attrs ⇒ Object
readonly
Returns the value of attribute header_attrs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#initialize(table, name, options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #is_sorted?(dir = nil) ⇒ Boolean
- #show_sort? ⇒ Boolean
- #value(row) ⇒ Object
Constructor Details
#initialize(table, name, options = {}, &block) ⇒ Column
Returns a new instance of Column.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tableficate/column.rb', line 5 def initialize(table, name, = {}, &block) @table = table @name = name @block = block @header = .delete(:header) || name.to_s.titleize @header_attrs = .delete(:header_attrs) || {} @cell_attrs = .delete(:cell_attrs) || {} @show_sort = .delete(:show_sort) || false @attrs = end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def attrs @attrs end |
#cell_attrs ⇒ Object (readonly)
Returns the value of attribute cell_attrs.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def cell_attrs @cell_attrs end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def header @header end |
#header_attrs ⇒ Object (readonly)
Returns the value of attribute header_attrs.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def header_attrs @header_attrs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def name @name end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def table @table end |
Instance Method Details
#is_sorted?(dir = nil) ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/tableficate/column.rb', line 38 def is_sorted?(dir = nil) is_sorted = @table.current_sort[:column] == self.name is_sorted = @table.current_sort[:dir] == dir if is_sorted and dir is_sorted end |
#show_sort? ⇒ Boolean
34 35 36 |
# File 'lib/tableficate/column.rb', line 34 def show_sort? @show_sort end |
#value(row) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tableficate/column.rb', line 20 def value(row) if @block output = @block.call(row) if output.is_a?(ActionView::OutputBuffer) '' else output = output.html_safe if output.respond_to? :html_safe output end else row.send(@name) end end |