Blame view

lib/syspro/business_objects/parsers/combrw_parser.rb 1.41 KB
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
  # frozen_string_literal: true
  
96149efa   Isaac Lewis   working query browse
3
4
5
6
  module Syspro
    module BusinessObjects
      module Parsers
        class ComBrwParser
0f29247c   Isaac Lewis   add comfch and co...
7
          attr_reader :doc
96149efa   Isaac Lewis   working query browse
8
  
0f29247c   Isaac Lewis   add comfch and co...
9
10
11
12
13
          def initialize(doc)
            @doc = doc
          end
  
          def parse
dc8aa5b6   Joe Weakley   Rubocop corrections
14
15
16
            next_prev_key = doc.first_element_child.xpath('NextPrevKey')
            next_prev_key_obj = next_prev_key.children.map do |el|
              next if el.name == 'text'
96149efa   Isaac Lewis   working query browse
17
18
19
20
              {
                name: el.name,
                text: el.text
              }
dc8aa5b6   Joe Weakley   Rubocop corrections
21
            end.compact
96149efa   Isaac Lewis   working query browse
22
  
dc8aa5b6   Joe Weakley   Rubocop corrections
23
24
25
            header_details = doc.first_element_child.xpath('HeaderDetails')
            header_details_obj = header_details.children.map do |el|
              next if el.name == 'text'
96149efa   Isaac Lewis   working query browse
26
27
28
29
              {
                name: el.name,
                text: el.text
              }
dc8aa5b6   Joe Weakley   Rubocop corrections
30
            end.compact
96149efa   Isaac Lewis   working query browse
31
32
  
            rows = doc.first_element_child.xpath('Row')
dc8aa5b6   Joe Weakley   Rubocop corrections
33
34
            rows_obj = rows.flat_map do |el|
              el.elements.map do |inner|
96149efa   Isaac Lewis   working query browse
35
                {
0f29247c   Isaac Lewis   add comfch and co...
36
37
38
                  name: inner.name,
                  value: inner.xpath('Value').text,
                  data_type: inner.xpath('DataType').text
96149efa   Isaac Lewis   working query browse
39
                }
dc8aa5b6   Joe Weakley   Rubocop corrections
40
41
              end
            end.compact
96149efa   Isaac Lewis   working query browse
42
43
  
            BrowseObject.new(
dc8aa5b6   Joe Weakley   Rubocop corrections
44
              doc.first_element_child.xpath('Title').text,
96149efa   Isaac Lewis   working query browse
45
46
47
48
49
50
51
52
53
54
55
              rows_obj,
              next_prev_key_obj,
              header_details_obj
            )
          end
  
          BrowseObject = Struct.new(:title, :rows, :next_prev_key, :header_details)
        end
      end
    end
  end