Class: Coalla::TableFormatter::MethodFormatter
- Inherits:
-
Object
- Object
- Coalla::TableFormatter::MethodFormatter
- Defined in:
- lib/coalla/builders/table_formatter.rb
Constant Summary collapse
- FORMATS =
{ boolean: BooleanFormatter.new, date: DateFormatter.new, datetime: DateFormatter.new('%d.%m.%Y %H:%M'), enumerize: EnumerizeFormatter.new }
Instance Method Summary collapse
- #align ⇒ Object
- #align=(value) ⇒ Object
- #format_value(item, format) ⇒ Object
-
#initialize(method, type) ⇒ MethodFormatter
constructor
A new instance of MethodFormatter.
- #respond_to?(method) ⇒ Boolean
Constructor Details
#initialize(method, type) ⇒ MethodFormatter
Returns a new instance of MethodFormatter.
73 74 75 76 |
# File 'lib/coalla/builders/table_formatter.rb', line 73 def initialize(method, type) @method = method @formatter = FORMATS[type] end |
Instance Method Details
#align ⇒ Object
82 83 84 |
# File 'lib/coalla/builders/table_formatter.rb', line 82 def align @align || @formatter.respond_to?(:align) && @formatter.align || :left end |
#align=(value) ⇒ Object
86 87 88 |
# File 'lib/coalla/builders/table_formatter.rb', line 86 def align=(value) @align = value end |
#format_value(item, format) ⇒ Object
78 79 80 |
# File 'lib/coalla/builders/table_formatter.rb', line 78 def format_value(item, format) @formatter.format_value(item.send(@method), format) end |
#respond_to?(method) ⇒ Boolean
90 91 92 93 |
# File 'lib/coalla/builders/table_formatter.rb', line 90 def respond_to?(method) return (@align.present? || @formatter.respond_to?(method)) if method == :align super end |