Skip to content

Commit ecdb851

Browse files
committed
Support multiple versions of qbxml
1 parent 6cd42c0 commit ecdb851

16 files changed

+334635
-26728
lines changed

lib/qbxml/hash.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ def self.hash_to_xml(hash, opts = {})
4545
opts[:indent] ||= 2
4646
opts[:root] ||= :hash
4747
opts[:attributes] ||= (hash.delete(ATTR_ROOT) || {})
48-
opts[:xml_directive] ||= [:xml, {}]
4948
opts[:builder] ||= Builder::XmlMarkup.new(indent: opts[:indent])
5049
opts[:skip_types] = true unless opts.key?(:skip_types)
5150
opts[:skip_instruct] = false unless opts.key?(:skip_instruct)
5251
builder = opts[:builder]
5352

5453
unless opts.delete(:skip_instruct)
55-
builder.instruct!(opts[:xml_directive].first, opts[:xml_directive].last)
54+
builder.instruct!(opts[:schema], version: opts[:version])
5655
end
5756

5857
builder.tag!(opts[:root], opts.delete(:attributes)) do

lib/qbxml/qbxml.rb

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ class Qbxml
44
SCHEMA_PATH = File.expand_path('../../../schema', __FILE__)
55

66
SCHEMAS = {
7-
qb: "#{SCHEMA_PATH}/qbxmlops70.xml",
8-
qbpos: "#{SCHEMA_PATH}/qbposxmlops30.xml"
7+
qb: {
8+
"2.0" => "#{SCHEMA_PATH}/qbxmlops20.xml",
9+
"CA3.0" => "#{SCHEMA_PATH}/qbxmlopsCA30.xml",
10+
"3.0" => "#{SCHEMA_PATH}/qbxmlops30.xml",
11+
"4.0" => "#{SCHEMA_PATH}/qbxmlops40.xml",
12+
"4.1" => "#{SCHEMA_PATH}/qbxmlops41.xml",
13+
"5.0" => "#{SCHEMA_PATH}/qbxmlops50.xml",
14+
"6.0" => "#{SCHEMA_PATH}/qbxmlops60.xml",
15+
"7.0" => "#{SCHEMA_PATH}/qbxmlops70.xml",
16+
"8.0" => "#{SCHEMA_PATH}/qbxmlops80.xml",
17+
"10.0" => "#{SCHEMA_PATH}/qbxmlops100.xml",
18+
"11.0" => "#{SCHEMA_PATH}/qbxmlops110.xml",
19+
"12.0" => "#{SCHEMA_PATH}/qbxmlops120.xml",
20+
"13.0" => "#{SCHEMA_PATH}/qbxmlops130.xml"
21+
},
22+
qbpos: {
23+
"3.0" => "#{SCHEMA_PATH}/qbposxmlops30.xml"
24+
}
925
}.freeze
1026

1127
HIDE_IVARS = [:@doc].freeze
1228

13-
def initialize(key = :qb)
14-
@schema = key
15-
@doc = parse_schema(key)
29+
def initialize(key = :qb, version = "7.0")
30+
@schema = key
31+
@version = version
32+
@doc = parse_schema(key, version)
1633
end
1734

1835
# returns all xml nodes matching a specified pattern
@@ -38,7 +55,7 @@ def to_qbxml(hash, opts = {})
3855
hash = namespace_qbxml_hash(hash) unless opts[:no_namespace]
3956
validate_qbxml_hash(hash) if opts[:validate]
4057

41-
Qbxml::Hash.to_xml(hash, xml_directive: XML_DIRECTIVES[@schema])
58+
Qbxml::Hash.to_xml(hash, schema: XML_DIRECTIVES[@schema], version: @version)
4259
end
4360

4461
# converts qbxml to a hash
@@ -64,12 +81,14 @@ def inspect
6481

6582
# private
6683

67-
def parse_schema(key)
68-
File.open(select_schema(key)) { |f| Nokogiri::XML(f) }
84+
def parse_schema(key, version)
85+
File.open(select_schema(key, version)) { |f| Nokogiri::XML(f) }
6986
end
7087

71-
def select_schema(schema_key)
72-
SCHEMAS[schema_key] || raise("invalid schema, must be one of #{SCHEMA.keys.inspect}")
88+
def select_schema(schema_key, version)
89+
raise "invalid schema '#{schema_key}', must be one of #{SCHEMAS.keys.inspect}" if !SCHEMAS.has_key?(schema_key)
90+
raise "invalid version '#{version}' for schema #{schema_key}, must be one of #{SCHEMAS[schema_key].keys.inspect}" if !SCHEMAS[schema_key].has_key?(version)
91+
return SCHEMAS[schema_key][version]
7392
end
7493

7594
# hash to qbxml

lib/qbxml/types.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Qbxml::Types
22

33
XML_DIRECTIVES = {
4-
:qb => [:qbxml, { version: '7.0' }],
5-
:qbpos => [:qbposxml, { version: '3.0' }]
4+
:qb => :qbxml,
5+
:qbpos => :qbposxml
66
}.freeze
77

88
FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}

schema/qbxmlops100.xml

Lines changed: 30100 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops110.xml

Lines changed: 32241 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops120.xml

Lines changed: 34129 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops130.xml

Lines changed: 35788 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops20.xml

Lines changed: 13140 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops30.xml

Lines changed: 18229 additions & 0 deletions
Large diffs are not rendered by default.

schema/qbxmlops40.xml

Lines changed: 19811 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)