Blame view

lib/syspro/business_objects/parsers/invsws_parser.rb 1.26 KB
762ae45f   chadzink   Added InvSws Busi...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  # frozen_string_literal: true
  
  module Syspro
    module BusinessObjects
      module Parsers
        class InvSwsParser
          attr_reader :doc
  
          def initialize(doc)
            @doc = doc
          end
  
          def parse
            {
              "key": {
                "stock_code": doc.xpath("//item/key/stockcode").map{|e| e.text}.first,
                "warehouse": doc.xpath("//item/key/stockcode").map{|e| e.text}.first
              },
              "reacords_read": doc.xpath("//StatusOfItems/RecordsRead").map{|e| e.text}.first,
              "reacords_invalid": doc.xpath("//StatusOfItems/RecordsInvalid").map{|e| e.text}.first,
f4259c1e   Samuel J Clopton   fix tests and add...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
              "error_numbers": doc.xpath("//ErrorNumber").map{|e| e.text},
              "errors": map_errors
            }
          end
  
          def map_errors
            doc.xpath('//ErrorNumber/..').map do |error_parent_node|
              map_error_parent(error_parent_node)
            end
          end
  
          def map_error_parent(error_parent_node)
            {
              node_name: error_parent_node.name,
              error_number: error_parent_node.xpath('//ErrorNumber').text,
              error_desc: error_parent_node.xpath('//ErrorDescription').text,
              value: error_parent_node.xpath('//Value').text
762ae45f   chadzink   Added InvSws Busi...
38
39
40
41
42
43
            }
          end
        end
      end
    end
  end