Blame view

lib/syspro/business_objects/parsers/comfnd_parser.rb 1.04 KB
0f29247c   Isaac Lewis   add comfch and co...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  module Syspro
    module BusinessObjects
      module Parsers
        class ComFndParser
          attr_reader :doc
  
          def initialize(doc)
            @doc = doc
          end
  
          def parse
            header_details = doc.first_element_child.xpath("HeaderDetails")
            header_details_obj = header_details.children.map { |el|
              if el.name == "text"
                next
              end
              {
                name: el.name,
                text: el.text
              }
            }.compact
  
            rows = doc.first_element_child.xpath('Row')
            rows_obj = rows.map { |el|
              el.elements.map { |inner|
                {
                  name: inner.name,
                  value: inner.children.text
                }
              }
            }.flatten(1).compact
  
724c1cbe   Isaac Lewis   add to readme; fi...
33
            QueryObject.new(
0f29247c   Isaac Lewis   add comfch and co...
34
35
36
37
38
39
              header_details_obj,
              rows_obj,
              doc.first_element_child.xpath('//RowsReturned').text.to_i
            )
          end
  
724c1cbe   Isaac Lewis   add to readme; fi...
40
          QueryObject = Struct.new(:header_details, :rows, :row_count)
0f29247c   Isaac Lewis   add comfch and co...
41
42
43
44
        end
      end
    end
  end