Module: Nazar::Formatter::ActiveRecordInterface

Included in:
ActiveRecordCollection, ActiveRecordItem
Defined in:
lib/nazar/formatter/active_record_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/active_record_interface.rb', line 6

def attributes
  @attributes
end

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#cellsObject



16
17
18
19
20
21
22
# File 'lib/nazar/formatter/active_record_interface.rb', line 16

def cells
  @cells ||= collection.map do |item|
    item.attributes.map do |column, value|
      CellFormatter.new(value, type: klass.type_for_attribute(column).type).format
    end
  end
end

#headersObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  !!(attributes && klass)
end