class Nazar::Formatter::CSVTable
Constants
- BOOLEAN_VALUES
Attributes
collection[R]
Public Class Methods
new(collection)
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 8 def initialize(collection) @collection = collection end
valid?(data)
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 12 def self.valid?(data) data.is_a?(CSV::Table) end
Public Instance Methods
cells()
click to toggle source
# 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()
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 20 def headers HeadersFormatter.new(collection.headers).format end
summary()
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 32 def summary collection.size end
valid?()
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 16 def valid? !!collection && !collection.empty? end
Private Instance Methods
detect_type(value)
click to toggle source
# File lib/nazar/formatter/csv_table.rb, line 40 def detect_type(value) case value when ->(val) { BOOLEAN_VALUES.include?(val.to_s.downcase) } :boolean when Numeric :numeric else :string end end