Blame view

lib/syspro/business_objects/parsers/comfnd_parser.rb 1.04 KB
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
  # frozen_string_literal: true
  
0f29247c   Isaac Lewis   add comfch and co...
3
4
5
6
7
8
9
10
11
12
13
  module Syspro
    module BusinessObjects
      module Parsers
        class ComFndParser
          attr_reader :doc
  
          def initialize(doc)
            @doc = doc
          end
  
          def parse
dc8aa5b6   Joe Weakley   Rubocop corrections
14
15
16
            header_details = doc.first_element_child.xpath('HeaderDetails')
            header_details_obj = header_details.children.map do |el|
              next if el.name == 'text'
0f29247c   Isaac Lewis   add comfch and co...
17
18
19
20
              {
                name: el.name,
                text: el.text
              }
dc8aa5b6   Joe Weakley   Rubocop corrections
21
            end.compact
0f29247c   Isaac Lewis   add comfch and co...
22
23
  
            rows = doc.first_element_child.xpath('Row')
dc8aa5b6   Joe Weakley   Rubocop corrections
24
25
            rows_obj = rows.flat_map do |el|
              el.elements.map do |inner|
0f29247c   Isaac Lewis   add comfch and co...
26
27
28
29
                {
                  name: inner.name,
                  value: inner.children.text
                }
dc8aa5b6   Joe Weakley   Rubocop corrections
30
31
              end
            end.compact
0f29247c   Isaac Lewis   add comfch and co...
32
  
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