Module: Nazar::Formatter::SequelInterface

Included in:
SequelCollection, SequelItem
Defined in:
lib/nazar/formatter/sequel_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/nazar/formatter/sequel_interface.rb', line 6

def attributes
  @attributes
end

#collectionObject (readonly)

Returns the value of attribute collection.



6
7
8
# File 'lib/nazar/formatter/sequel_interface.rb', line 6

def collection
  @collection
end

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/nazar/formatter/sequel_interface.rb', line 6

def klass
  @klass
end

Instance Method Details

#cellsObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nazar/formatter/sequel_interface.rb', line 16

def cells
  @cells ||= begin
    schema = collection.first.db_schema

    collection.map do |item|
      item.values.map do |column, value|
        CellFormatter.new(value, type: schema.dig(column, :type)).format
      end
    end
  end
end

#headersObject



12
13
14
# File 'lib/nazar/formatter/sequel_interface.rb', line 12

def headers
  HeadersFormatter.new(attributes.keys).format
end

#summaryObject



28
29
30
# File 'lib/nazar/formatter/sequel_interface.rb', line 28

def summary
  collection.size
end

#valid?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/nazar/formatter/sequel_interface.rb', line 8

def valid?
  !!attributes
end