Class: Nazar::Formatter::CSVTable
- Inherits:
-
Object
- Object
- Nazar::Formatter::CSVTable
- Defined in:
- lib/nazar/formatter/csv_table.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Class Method Summary collapse
Instance Method Summary collapse
- #cells ⇒ Object
- #headers ⇒ Object
-
#initialize(collection) ⇒ CSVTable
constructor
A new instance of CSVTable.
- #summary ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(collection) ⇒ CSVTable
Returns a new instance of CSVTable.
8 9 10 |
# File 'lib/nazar/formatter/csv_table.rb', line 8 def initialize(collection) @collection = collection end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
6 7 8 |
# File 'lib/nazar/formatter/csv_table.rb', line 6 def collection @collection end |
Class Method Details
.valid?(data) ⇒ Boolean
12 13 14 |
# File 'lib/nazar/formatter/csv_table.rb', line 12 def self.valid?(data) data.is_a?(CSV::Table) end |
Instance Method Details
#cells ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/nazar/formatter/csv_table.rb', line 24 def cells @cells ||= collection.map do |item| item.fields.map do |value| CellFormatter.new(value, type: detect_type(value)).format end end end |
#headers ⇒ Object
20 21 22 |
# File 'lib/nazar/formatter/csv_table.rb', line 20 def headers HeadersFormatter.new(collection.headers).format end |
#summary ⇒ Object
32 33 34 |
# File 'lib/nazar/formatter/csv_table.rb', line 32 def summary collection.size end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/nazar/formatter/csv_table.rb', line 16 def valid? !!collection && !collection.empty? end |