Class: Tableficate::Column
- Inherits:
-
Object
- Object
- Tableficate::Column
- Defined in:
- lib/tableficate/column.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#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 |
# File 'lib/tableficate/column.rb', line 5 def initialize(table, name, = {}, &block) @table = table @name = name @options = @block = block @header = @options.delete(:header) || name.to_s.titleize end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/tableficate/column.rb', line 3 def header @header 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
32 33 34 35 36 37 |
# File 'lib/tableficate/column.rb', line 32 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
28 29 30 |
# File 'lib/tableficate/column.rb', line 28 def show_sort? !!@options[:show_sort] end |
#value(row) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tableficate/column.rb', line 14 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 |