Class: Tabletastic::TableField
- Inherits:
-
Object
- Object
- Tabletastic::TableField
- Defined in:
- lib/tabletastic/table_field.rb
Constant Summary collapse
- @@association_methods =
%w[to_label display_name full_name name title username login value to_str to_s]
Instance Attribute Summary collapse
-
#cell_html ⇒ Object
Returns the value of attribute cell_html.
-
#heading ⇒ Object
Returns the value of attribute heading.
-
#heading_html ⇒ Object
Returns the value of attribute heading_html.
-
#method_or_proc ⇒ Object
Returns the value of attribute method_or_proc.
Instance Method Summary collapse
- #cell_data(record) ⇒ Object
-
#initialize(*args, &proc) ⇒ TableField
constructor
A new instance of TableField.
Constructor Details
#initialize(*args, &proc) ⇒ TableField
Returns a new instance of TableField.
9 10 11 12 13 14 15 16 |
# File 'lib/tabletastic/table_field.rb', line 9 def initialize(*args, &proc) = args. method = args.first.to_sym @method_or_proc = block_given? ? proc : method @cell_html, @heading_html = [:cell_html], [:heading_html] @klass = .delete(:klass) @heading = .delete(:heading) || @klass.try(:human_attribute_name, method.to_s) || method.to_s.humanize end |
Instance Attribute Details
#cell_html ⇒ Object
Returns the value of attribute cell_html.
7 8 9 |
# File 'lib/tabletastic/table_field.rb', line 7 def cell_html @cell_html end |
#heading ⇒ Object
Returns the value of attribute heading.
7 8 9 |
# File 'lib/tabletastic/table_field.rb', line 7 def heading @heading end |
#heading_html ⇒ Object
Returns the value of attribute heading_html.
7 8 9 |
# File 'lib/tabletastic/table_field.rb', line 7 def heading_html @heading_html end |
#method_or_proc ⇒ Object
Returns the value of attribute method_or_proc.
7 8 9 |
# File 'lib/tabletastic/table_field.rb', line 7 def method_or_proc @method_or_proc end |
Instance Method Details
#cell_data(record) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tabletastic/table_field.rb', line 18 def cell_data(record) # Get the attribute or association in question result = send_or_call(record, method_or_proc) # If we already have a string, just return it return result if result.is_a?(String) # If we don't have a string, its likely an association # Try to detect which method to use for stringifying the attribute to_string = detect_string_method(result) result.send(to_string) if to_string end |