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') next nil if value.blank? parse_row_value(value) end end
parse_row_value(value)
click to toggle source
# File lib/quickbooks/model/report.rb, line 46 def parse_row_value(value) # does it look like a number? if value =~ /\A\-?[0-9\.]+\Z/ BigDecimal(value) else value end rescue ArgumentError value end