Class: Nazar::Formatter::CSVTable

Inherits:
Object
  • Object
show all
Defined in:
lib/nazar/formatter/csv_table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#collectionObject (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

Returns:

  • (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

#cellsObject



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

#headersObject



20
21
22
# File 'lib/nazar/formatter/csv_table.rb', line 20

def headers
  HeadersFormatter.new(collection.headers).format
end

#summaryObject



32
33
34
# File 'lib/nazar/formatter/csv_table.rb', line 32

def summary
  collection.size
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/nazar/formatter/csv_table.rb', line 16

def valid?
  !!collection && !collection.empty?
end