module Xeroizer::Report::CellXmlHelper::ClassMethods

Public Instance Methods

build_from_node(node) click to toggle source

Create an instance of Cell from the node.

Additionally, parse the attributes and return them as a hash to the cell. If a cell's attributes look like:

<Attributes>
  <Attribute>
    <Value>1335b8b2-4d63-4af8-937f-04087ae2e36e</Value>
    <Id>account</Id>
  </Attribute>
</Attributes>

Return a hash like:

{
  'account' => '1335b8b2-4d63-4af8-937f-04087ae2e36e'
}
# File lib/xeroizer/report/cell_xml_helper.rb, line 31
def build_from_node(node)
  cell = new
  node.elements.each do | element |
    case element.name.to_s
      when 'Value' then cell.value = parse_value(element.text)
      when 'Attributes'
        element.elements.each do | attribute_node |
          (id, value) = parse_attribute(attribute_node)
          cell.attributes[id] = value
        end
    end
  end
  cell
end

Protected Instance Methods

parse_attribute(attribute_node) click to toggle source
# File lib/xeroizer/report/cell_xml_helper.rb, line 56
def parse_attribute(attribute_node)
  id = nil
  value = nil
  attribute_node.elements.each do | element |
    case element.name.to_s
      when 'Id'     then id = element.text
      when 'Value'  then value = element.text
    end
  end
  [id, value]
end
parse_value(value) click to toggle source
# File lib/xeroizer/report/cell_xml_helper.rb, line 48
def parse_value(value)
  case value
    when /\A[-]?\d+(\.\d+)?\z/                      then BigDecimal(value)
    when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\z/  then Time.xmlschema(value)
    else                                            value
  end
end