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
|
8d1385a3
Sam Clopton
Update combrw que...
|
7
8
|
BrowseObject = Struct.new(:headers, :rows, :next_key, :prev_key, :fwd, :back, :key)
|
0f29247c
Isaac Lewis
add comfch and co...
|
9
|
attr_reader :doc
|
96149efa
Isaac Lewis
working query browse
|
10
|
|
0f29247c
Isaac Lewis
add comfch and co...
|
11
12
13
14
15
|
def initialize(doc)
@doc = doc
end
def parse
|
8d1385a3
Sam Clopton
Update combrw que...
|
16
17
18
19
20
21
|
prev_key = doc.xpath('//NextPrevKey/PrevKey').text
next_key = doc.xpath('//NextPrevKey/NextKey').text
fwd = doc.xpath('//NextPrevKey/Fwd').text.casecmp('true').zero?
back = doc.xpath('//NextPrevKey/Back').text.casecmp('true').zero?
headers = doc.xpath('//HeaderDetails/Header').map { |h| h.text }
key = doc.xpath('//HeaderDetails/Key').text
|
96149efa
Isaac Lewis
working query browse
|
22
|
|
8d1385a3
Sam Clopton
Update combrw que...
|
23
24
25
26
27
28
|
rows = doc.xpath('//Row').map do |row|
columns = row.children.select { |n| n.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT }
columns.each_with_object({}) do |column, hash|
hash[column.name] = column.children
.find { |child| child.name == 'Value' }
.text
|
dc8aa5b6
Joe Weakley
Rubocop corrections
|
29
|
end
|
8d1385a3
Sam Clopton
Update combrw que...
|
30
|
end
|
96149efa
Isaac Lewis
working query browse
|
31
32
|
BrowseObject.new(
|
8d1385a3
Sam Clopton
Update combrw que...
|
33
34
35
36
37
38
39
|
headers,
rows,
next_key,
prev_key,
fwd,
back,
key
|
96149efa
Isaac Lewis
working query browse
|
40
41
|
)
end
|
96149efa
Isaac Lewis
working query browse
|
42
43
44
45
|
end
end
end
end
|