class Quickbooks::Model::Report

Attributes

xml[RW]

Public Instance Methods

all_rows() click to toggle source
# File lib/quickbooks/model/report.rb, line 7
def all_rows
  @all_rows ||= xml.css("ColData:first-child").map {|node| parse_row(node.parent) }
end
columns() click to toggle source
# File lib/quickbooks/model/report.rb, line 11
def columns
  @columns ||= begin
    nodes = xml.css('Column')
    nodes.map do |node|
      # There is also a ColType field, but it does not seem valuable to capture
      node.at('ColTitle').content
    end
  end
end
find_row(label) click to toggle source
# File lib/quickbooks/model/report.rb, line 21
def find_row(label)
  all_rows.find {|r| r[0] == label }
end

Private Instance Methods

parse_row(row_node) click to toggle source

Parses the given row:

 <Row type="Data">
   <ColData value="Checking" id="35"/>
   <ColData value="1201.00"/>
   <ColData value="200.50"/>
 </Row>

To:
 ['Checking', BigDecimal(1201.00), BigDecimal(200.50)]
# File lib/quickbooks/model/report.rb, line 36
def parse_row(row_node)
  row_node.elements.map.with_index do |el, i|
    value = el.attr('value')

    if i.zero? # Return the first column as a string, its the label.
      value
    elsif value.blank?
      nil
    else
      BigDecimal(value)
    end
  end
end