Sha256: e7786938a614c045a890b32ce433efba59919e5f1a31c85c89939fbcf9cd046f

Contents?: true

Size: 1.65 KB

Versions: 56

Compression:

Stored size: 1.65 KB

Contents

module Xeroizer
  module Report
    module XmlHelper
      
      def self.included(base)
        base.extend(ClassMethods)
        base.send :include, InstanceMethods
      end
      
      module ClassMethods
        
        public
        
          def build_from_node(node, factory)
            report = new(factory)
            
            extract_report_details(report, node)
            
            rows = node.xpath("Rows/Row")
            extract_rows(report, rows) if rows && rows.size > 0
            
            report
          end

        protected
        
          # Extract header details for the report response.
          def extract_report_details(report, node)
            node.elements.each do | element |
              case element.name.to_s
                when 'ReportID'       then report.id = element.text
                when 'ReportName'     then report.name = element.text
                when 'ReportType'     then report.type = element.text
                when 'ReportDate'     then report.date = Date.parse(element.text)
                when 'UpdatedDateUTC' then report.updated_at = Time.parse(element.text)
                when 'ReportTitles'
                  element.elements.each do | title_element |
                    report.titles << title_element.text
                  end
              end
            end
          end
          
          # Extract the report rows
          def extract_rows(report, rows)
            rows.each do | row_node |
              report.rows << Row.build_from_node(row_node, report)
            end
          end
          
      end
      
      module InstanceMethods
      end
      
    end
  end
end

Version data entries

56 entries across 56 versions & 3 rubygems

Version Path
xeroizer-3.0.1 lib/xeroizer/report/xml_helper.rb
xeroizer-3.0.0 lib/xeroizer/report/xml_helper.rb
xeroizer-3-pre-beta-3.0.0.pre.beta lib/xeroizer/report/xml_helper.rb
xeroizer-2.20.0 lib/xeroizer/report/xml_helper.rb
xeroizer-2.19.0 lib/xeroizer/report/xml_helper.rb
xeroizer-2.18.1 lib/xeroizer/report/xml_helper.rb
xeroizer-2.17.1 lib/xeroizer/report/xml_helper.rb
xeroizer-2.16.5 lib/xeroizer/report/xml_helper.rb
xeroizer-2.16.4 lib/xeroizer/report/xml_helper.rb
xeroizer-2.16.3 lib/xeroizer/report/xml_helper.rb
xeroizer-2.16.1 lib/xeroizer/report/xml_helper.rb
xeroizer-2.16.0 lib/xeroizer/report/xml_helper.rb
xeroizer-2.15.9 lib/xeroizer/report/xml_helper.rb
xeroizer-2.15.8 lib/xeroizer/report/xml_helper.rb
xeroizer-2.15.7 lib/xeroizer/report/xml_helper.rb
xeroizer-2.15.6 lib/xeroizer/report/xml_helper.rb
xeroizer-float-2.15.5.2 lib/xeroizer/report/xml_helper.rb
xeroizer-float-2.15.5.1 lib/xeroizer/report/xml_helper.rb
xeroizer-2.15.5 lib/xeroizer/report/xml_helper.rb
xeroizer-float-2.15.3.16 lib/xeroizer/report/xml_helper.rb