class Nazar::Formatter::Generic
Attributes
collection[R]
item[R]
Public Class Methods
new(collection)
click to toggle source
# File lib/nazar/formatter/generic.rb, line 8 def initialize(collection) @collection = Array(collection) @item = collection.first end
valid?(data)
click to toggle source
# File lib/nazar/formatter/generic.rb, line 29 def self.valid?(data) item = data.first compatible = item.respond_to?(:keys) && item.respond_to?(:values) data.is_a?(Enumerable) && (item.is_a?(Struct) || compatible) end
Public Instance Methods
cells()
click to toggle source
# File lib/nazar/formatter/generic.rb, line 17 def cells @cells ||= collection.map do |item| item.values.map do |value| CellFormatter.new(value).format end end end
headers()
click to toggle source
# File lib/nazar/formatter/generic.rb, line 13 def headers HeadersFormatter.new(raw_headers).format end
summary()
click to toggle source
# File lib/nazar/formatter/generic.rb, line 25 def summary collection.size end
valid?()
click to toggle source
# File lib/nazar/formatter/generic.rb, line 36 def valid? !!item && !raw_headers.empty? end
Private Instance Methods
raw_headers()
click to toggle source
# File lib/nazar/formatter/generic.rb, line 44 def raw_headers @raw_headers ||= if item.is_a?(Struct) item.members elsif item.respond_to?(:keys) item.keys else [] end end