qbxml 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11572014f70b00b684710498b5f2072e4c716a34
4
- data.tar.gz: d8d4be361ed0a330345637c270221fb06f1f03c0
3
+ metadata.gz: 6c56d438dd81ddd6797733fb49d66380275dd355
4
+ data.tar.gz: b9e9a280fab05871d6d0ad11de67647edc381f05
5
5
  SHA512:
6
- metadata.gz: bfac0afceeca6efd56a5459f0c21b1180d76c6705ff070a30d254db62c35255015e66d1be3ecc6fe88272b0f351ca18d06e38c0f32e5e9b810c871d324720436
7
- data.tar.gz: eb5a9c9a4346d810b638000608ef37f02d382a5dc9683576bc67f757af49a0b0e66fbcb1bcd691c171bd1ea6d861941fd80510175857ebf83d69bc95d56feb47
6
+ metadata.gz: 6667cb6c3aa3064f6a30b5405b1b58141f7e286d16ccdec61fe7068af9327d09d542e51ec64228d6d5206655472869a5e42ffe0e44a225ebf52deb604489e76c
7
+ data.tar.gz: 4299dd57e9015bb93eec46c7491389af1ac501920f4cec8d86d84e77e0174312b4cc5094f24de864804949570f7ccfcabecd1cbf8f12e8483fdfe84762ba1906
@@ -1,6 +1,22 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 1.9
4
4
  - 2.0
5
5
  - 2.1
6
6
  - 2.2
7
+ - 2.3.1
8
+
9
+ gemfile:
10
+ - gemfiles/rails_5.0.gemfile
11
+ - gemfiles/rails_4.2.gemfile
12
+ - gemfiles/rails_4.1.gemfile
13
+
14
+ matrix:
15
+ exclude:
16
+ - rvm: 2.0
17
+ gemfile: gemfiles/rails_5.0.gemfile
18
+ - rvm: 2.1
19
+ gemfile: gemfiles/rails_5.0.gemfile
20
+
21
+ before_install:
22
+ - if ruby --version | cut -d ' ' -f 2 | grep -q 2.1.5p273 ; then gem update --system 2.4.8; fi
@@ -0,0 +1,11 @@
1
+ appraise "rails-4.1" do
2
+ gem "activesupport", "~> 4.1.0"
3
+ end
4
+
5
+ appraise "rails-4.2" do
6
+ gem "activesupport", "~> 4.2.0"
7
+ end
8
+
9
+ appraise "rails-5.0" do
10
+ gem "activesupport", "~> 5.0.0"
11
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ qbxml (0.3.0)
5
+ activesupport (>= 4.1.0)
6
+ builder (~> 3.0)
7
+ nokogiri (~> 1.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.1.16)
13
+ i18n (~> 0.6, >= 0.6.9)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.1)
17
+ tzinfo (~> 1.1)
18
+ appraisal (2.1.0)
19
+ bundler
20
+ rake
21
+ thor (>= 0.14.0)
22
+ builder (3.2.2)
23
+ coderay (1.1.1)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ i18n (0.7.0)
27
+ json (1.8.3)
28
+ method_source (0.8.2)
29
+ mini_portile2 (2.1.0)
30
+ minitest (5.9.0)
31
+ nokogiri (1.6.8)
32
+ mini_portile2 (~> 2.1.0)
33
+ pkg-config (~> 1.1.7)
34
+ pkg-config (1.1.7)
35
+ pry (0.10.4)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.8.1)
38
+ slop (~> 3.4)
39
+ pry-nav (0.2.4)
40
+ pry (>= 0.9.10, < 0.11.0)
41
+ rake (11.2.2)
42
+ rspec (3.5.0)
43
+ rspec-core (~> 3.5.0)
44
+ rspec-expectations (~> 3.5.0)
45
+ rspec-mocks (~> 3.5.0)
46
+ rspec-core (3.5.2)
47
+ rspec-support (~> 3.5.0)
48
+ rspec-expectations (3.5.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.5.0)
51
+ rspec-mocks (3.5.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-support (3.5.0)
55
+ simplecov (0.12.0)
56
+ docile (~> 1.1.0)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.0)
60
+ slop (3.6.0)
61
+ thor (0.19.1)
62
+ thread_safe (0.3.5)
63
+ tzinfo (1.2.2)
64
+ thread_safe (~> 0.1)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activesupport (~> 4.1.0)
71
+ appraisal
72
+ pry
73
+ pry-nav
74
+ qbxml!
75
+ rake
76
+ rspec
77
+ simplecov
78
+
79
+ BUNDLED WITH
80
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ qbxml (0.3.0)
5
+ activesupport (>= 4.1.0)
6
+ builder (~> 3.0)
7
+ nokogiri (~> 1.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.2.7.1)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ appraisal (2.1.0)
19
+ bundler
20
+ rake
21
+ thor (>= 0.14.0)
22
+ builder (3.2.2)
23
+ coderay (1.1.1)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ i18n (0.7.0)
27
+ json (1.8.3)
28
+ method_source (0.8.2)
29
+ mini_portile2 (2.1.0)
30
+ minitest (5.9.0)
31
+ nokogiri (1.6.8)
32
+ mini_portile2 (~> 2.1.0)
33
+ pkg-config (~> 1.1.7)
34
+ pkg-config (1.1.7)
35
+ pry (0.10.4)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.8.1)
38
+ slop (~> 3.4)
39
+ pry-nav (0.2.4)
40
+ pry (>= 0.9.10, < 0.11.0)
41
+ rake (11.2.2)
42
+ rspec (3.5.0)
43
+ rspec-core (~> 3.5.0)
44
+ rspec-expectations (~> 3.5.0)
45
+ rspec-mocks (~> 3.5.0)
46
+ rspec-core (3.5.2)
47
+ rspec-support (~> 3.5.0)
48
+ rspec-expectations (3.5.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.5.0)
51
+ rspec-mocks (3.5.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-support (3.5.0)
55
+ simplecov (0.12.0)
56
+ docile (~> 1.1.0)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.0)
60
+ slop (3.6.0)
61
+ thor (0.19.1)
62
+ thread_safe (0.3.5)
63
+ tzinfo (1.2.2)
64
+ thread_safe (~> 0.1)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activesupport (~> 4.2.0)
71
+ appraisal
72
+ pry
73
+ pry-nav
74
+ qbxml!
75
+ rake
76
+ rspec
77
+ simplecov
78
+
79
+ BUNDLED WITH
80
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ qbxml (0.3.0)
5
+ activesupport (>= 4.1.0)
6
+ builder (~> 3.0)
7
+ nokogiri (~> 1.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.0.0.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ appraisal (2.1.0)
18
+ bundler
19
+ rake
20
+ thor (>= 0.14.0)
21
+ builder (3.2.2)
22
+ coderay (1.1.1)
23
+ concurrent-ruby (1.0.2)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ i18n (0.7.0)
27
+ json (2.0.2)
28
+ method_source (0.8.2)
29
+ mini_portile2 (2.1.0)
30
+ minitest (5.9.0)
31
+ nokogiri (1.6.8)
32
+ mini_portile2 (~> 2.1.0)
33
+ pkg-config (~> 1.1.7)
34
+ pkg-config (1.1.7)
35
+ pry (0.10.4)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.8.1)
38
+ slop (~> 3.4)
39
+ pry-nav (0.2.4)
40
+ pry (>= 0.9.10, < 0.11.0)
41
+ rake (11.2.2)
42
+ rspec (3.5.0)
43
+ rspec-core (~> 3.5.0)
44
+ rspec-expectations (~> 3.5.0)
45
+ rspec-mocks (~> 3.5.0)
46
+ rspec-core (3.5.2)
47
+ rspec-support (~> 3.5.0)
48
+ rspec-expectations (3.5.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.5.0)
51
+ rspec-mocks (3.5.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-support (3.5.0)
55
+ simplecov (0.12.0)
56
+ docile (~> 1.1.0)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.0)
60
+ slop (3.6.0)
61
+ thor (0.19.1)
62
+ thread_safe (0.3.5)
63
+ tzinfo (1.2.2)
64
+ thread_safe (~> 0.1)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activesupport (~> 5.0.0)
71
+ appraisal
72
+ pry
73
+ pry-nav
74
+ qbxml!
75
+ rake
76
+ rspec
77
+ simplecov
78
+
79
+ BUNDLED WITH
80
+ 1.12.5
@@ -85,15 +85,23 @@ private
85
85
  name = node.name
86
86
  schema = opts[:schema]
87
87
  opts[:typecast_cache] ||= {}
88
+ opts[:is_repetitive_cache] ||= {}
88
89
 
89
90
  # Insert node hash into parent hash correctly.
90
91
  case hash[name]
91
92
  when Array
92
93
  hash[name] << node_hash
93
94
  when Hash, String
95
+ # This parent has multiple nodes with the same name, but when we checked the first time,
96
+ # we found it is not defined as repetitive. I guess this means the schema is a liar.
94
97
  hash[name] = [hash[name], node_hash]
95
98
  else
96
- hash[name] = node_hash
99
+ # We didn't see this node name under this parent yet.
100
+ if is_repetitive?(schema, node.path, opts[:is_repetitive_cache])
101
+ hash[name] = [node_hash]
102
+ else
103
+ hash[name] = node_hash
104
+ end
97
105
  end
98
106
 
99
107
  # Handle child elements
@@ -142,6 +150,21 @@ private
142
150
  type_proc[value]
143
151
  end
144
152
 
153
+ # Determines if the node is repetitive. Just because something is repetitive doesn't mean it always repeats.
154
+ # For example, a customer query could return 1 result or 100, but in both cases, we should be returning an
155
+ # Array.
156
+ def self.is_repetitive?(schema, xpath, is_repetitive_cache)
157
+ # Yes, we are parsing comments.
158
+ comment_path = xpath.gsub(/\[\d+\]/,'') + "/comment()"
159
+ return is_repetitive_cache[comment_path] || parse_repetitive_from_comment(schema, comment_path)
160
+ end
161
+
162
+ def self.parse_repetitive_from_comment(schema, comment_path)
163
+ comment = schema.xpath(comment_path).first
164
+ return false if comment.nil?
165
+ return comment.text.include?('may rep')
166
+ end
167
+
145
168
  def self.deep_convert(hash, opts = {}, &block)
146
169
  hash.inject(self.new) do |h, (k,v)|
147
170
  k = k.to_s
@@ -5,7 +5,7 @@ module Qbxml::Types
5
5
  :qbpos => :qbposxml
6
6
  }.freeze
7
7
 
8
- FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}
8
+ FLOAT_CAST = Proc.new {|d| d ? d.to_f : 0.0}
9
9
  BOOL_CAST = Proc.new {|d| d ? (d.to_s.downcase == 'true' ? true : false) : false }
10
10
  DATE_CAST = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") }
11
11
  TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }
@@ -1,3 +1,3 @@
1
1
  class Qbxml
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency('activesupport', '>= 3.2.9')
20
+ gem.add_dependency('activesupport', '>= 4.1.0')
21
21
  gem.add_dependency('nokogiri', '~> 1.5')
22
22
  gem.add_dependency('builder', '~> 3.0')
23
23
 
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency('rspec')
27
27
  gem.add_development_dependency('simplecov')
28
28
  gem.add_development_dependency('rake')
29
+ gem.add_development_dependency('appraisal')
29
30
  end
@@ -26,5 +26,99 @@ class XmlToHashTest < Minitest::Test
26
26
  assert_equal h, qbxml.from_qbxml("<?qbxml version=\"7.0\"?>\n<QBXML>\n <QBXMLMsgsRq>\n <InvoiceQueryRq>\n <IncludeRetElement>TxnID</IncludeRetElement>\n <IncludeRetElement>RefNumber</IncludeRetElement>\n </InvoiceQueryRq>\n </QBXMLMsgsRq>\n</QBXML>\n")
27
27
  end
28
28
 
29
- end
29
+ def test_array_with_one_element
30
+ qbxml = Qbxml.new
31
+ h = {
32
+ "qbxml" => {
33
+ "xml_attributes" => {},
34
+ "qbxml_msgs_rs" => {
35
+ "xml_attributes" => {},
36
+ 'customer_query_rs' => {
37
+ "xml_attributes" => {},
38
+ 'customer_ret' => [{
39
+ "xml_attributes"=> {},
40
+ 'list_id' => 'abc'
41
+ }]
42
+ }
43
+ }
44
+ }
45
+ }
46
+ assert_equal h, qbxml.from_qbxml("<?qbxml version=\"7.0\"?>\n<QBXML>\n <QBXMLMsgsRs>\n <CustomerQueryRs>\n <CustomerRet><ListID>abc</ListID></CustomerRet>\n </CustomerQueryRs>\n </QBXMLMsgsRs>\n</QBXML>\n")
47
+ end
48
+
49
+ def test_float_percentage
50
+ qbxml = Qbxml.new
51
+ h = {
52
+ "qbxml" => {
53
+ "xml_attributes" => {},
54
+ "qbxml_msgs_rs" => {
55
+ "xml_attributes" => {},
56
+ "item_query_rs" => {
57
+ "xml_attributes" => {
58
+ "requestID" => "Retrieve items",
59
+ "statusCode" => "0",
60
+ "statusSeverity" => "Info",
61
+ "statusMessage" => "Status OK",
62
+ "iteratorRemainingCount" => "0",
63
+ "iteratorID" => "{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}"
64
+ },
65
+ "item_service_ret" => {
66
+ "xml_attributes" => {},
67
+ "list_id" => "80000005-1468535148",
68
+ "time_created" => "2016-07-14T15:25:48+00:00",
69
+ "time_modified" => "2016-07-14T15:25:48+00:00",
70
+ "edit_sequence" => "1468535148",
71
+ "name" => "let's get intuit",
72
+ "full_name" => "let's get intuit",
73
+ "is_active" => true,
74
+ "sublevel" => 0,
75
+ "sales_or_purchase" => {
76
+ "xml_attributes" => {},
77
+ "price_percent" => 18.0,
78
+ "account_ref" => {
79
+ "xml_attributes" => {},
80
+ "list_id" => "80000015-1457547358",
81
+ "full_name" => "Repairs and Maintenance"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ xml = <<-XML
91
+ <QBXML>
92
+ <QBXMLMsgsRs>
93
+ <ItemQueryRs requestID="Retrieve items"
94
+ statusCode="0"
95
+ statusSeverity="Info"
96
+ statusMessage="Status OK"
97
+ iteratorRemainingCount="0"
98
+ iteratorID="{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}">
99
+ <ItemServiceRet>
100
+ <ListID>80000005-1468535148</ListID>
101
+ <TimeCreated>2016-07-14T15:25:48+00:00</TimeCreated>
102
+ <TimeModified>2016-07-14T15:25:48+00:00</TimeModified>
103
+ <EditSequence>1468535148</EditSequence>
104
+ <Name>let's get intuit</Name>
105
+ <FullName>let's get intuit</FullName>
106
+ <IsActive>true</IsActive>
107
+ <Sublevel>0</Sublevel>
108
+ <SalesOrPurchase>
109
+ <PricePercent>18.0%</PricePercent>
110
+ <AccountRef>
111
+ <ListID>80000015-1457547358</ListID>
112
+ <FullName>Repairs and Maintenance</FullName>
113
+ </AccountRef>
114
+ </SalesOrPurchase>
115
+ </ItemServiceRet>
116
+ </ItemQueryRs>
117
+ </QBXMLMsgsRs>
118
+ </QBXML>
119
+ XML
30
120
 
121
+ assert_equal h, qbxml.from_qbxml(xml)
122
+ end
123
+
124
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Skryl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-03 00:00:00.000000000 Z
12
+ date: 2017-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 3.2.9
20
+ version: 4.1.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 3.2.9
27
+ version: 4.1.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: nokogiri
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: appraisal
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
126
140
  description: Quickbooks XML Parser
127
141
  email:
128
142
  - rut216@gmail.com
@@ -133,10 +147,17 @@ extra_rdoc_files: []
133
147
  files:
134
148
  - ".gitignore"
135
149
  - ".travis.yml"
150
+ - Appraisals
136
151
  - Gemfile
137
152
  - LICENSE.txt
138
153
  - README.md
139
154
  - Rakefile
155
+ - gemfiles/rails_4.1.gemfile
156
+ - gemfiles/rails_4.1.gemfile.lock
157
+ - gemfiles/rails_4.2.gemfile
158
+ - gemfiles/rails_4.2.gemfile.lock
159
+ - gemfiles/rails_5.0.gemfile
160
+ - gemfiles/rails_5.0.gemfile.lock
140
161
  - lib/qbxml.rb
141
162
  - lib/qbxml/hash.rb
142
163
  - lib/qbxml/qbxml.rb
@@ -200,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
221
  version: '0'
201
222
  requirements: []
202
223
  rubyforge_project:
203
- rubygems_version: 2.4.6
224
+ rubygems_version: 2.6.12
204
225
  signing_key:
205
226
  specification_version: 4
206
227
  summary: Quickbooks XML Parser and Validation Tool