Class: Nazar::Formatter::Generic
- Inherits:
-
Object
- Object
- Nazar::Formatter::Generic
- Defined in:
- lib/nazar/formatter/generic.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) ⇒ Generic
constructor
A new instance of Generic.
- #summary ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(collection) ⇒ Generic
Returns a new instance of Generic.
8 9 10 11 |
# File 'lib/nazar/formatter/generic.rb', line 8 def initialize(collection) @collection = Array(collection) @item = collection.first end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
6 7 8 |
# File 'lib/nazar/formatter/generic.rb', line 6 def collection @collection end |
Class Method Details
.valid?(data) ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/nazar/formatter/generic.rb', line 29 def self.valid?(data) return false unless data.is_a?(Enumerable) item = data&.first item.respond_to?(:keys) && item.respond_to?(:values) end |
Instance Method Details
#cells ⇒ Object
17 18 19 20 21 22 23 |
# 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 ⇒ Object
13 14 15 |
# File 'lib/nazar/formatter/generic.rb', line 13 def headers HeadersFormatter.new(raw_headers).format end |
#summary ⇒ Object
25 26 27 |
# File 'lib/nazar/formatter/generic.rb', line 25 def summary collection.size end |
#valid? ⇒ Boolean
36 37 38 |
# File 'lib/nazar/formatter/generic.rb', line 36 def valid? !!item && !raw_headers.empty? end |