match_point 0.0.1 → 0.0.2
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.
- data/lib/match_point/version.rb +1 -1
- data/lib/match_point/xml_instance.rb +57 -0
- data/lib/match_point.rb +1 -1
- data/spec/match_point_spec.rb +17 -4
- metadata +3 -6
- data/lib/match_point/bxml_response.rb +0 -26
- data/lib/match_point/some_class.rb +0 -7
- data/test/test_match_point.rb +0 -10
data/lib/match_point/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module MatchPoint
|
2
|
+
class XmlInstance
|
3
|
+
|
4
|
+
SPEC_NODE="MatchPointSpec"
|
5
|
+
|
6
|
+
def initialize template, xml, data = {}
|
7
|
+
@template= Nokogiri::XML(template)
|
8
|
+
@xml = Nokogiri::XML(xml)
|
9
|
+
@nodes_paths = {}
|
10
|
+
|
11
|
+
synchronize_object_to_xml
|
12
|
+
assign_values data
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_xml
|
16
|
+
@template.to_xml
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def assign_values data
|
22
|
+
data.each do |key, value|
|
23
|
+
specify_value value, node_path(key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def node_path node_name
|
28
|
+
@nodes_paths[node_name]
|
29
|
+
end
|
30
|
+
|
31
|
+
def specify_value value, path
|
32
|
+
@template.xpath(remove_spec_node_from(path)).first.content = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def synchronize_object_to_xml
|
36
|
+
nodes_in_template = @template.xpath("//#{SPEC_NODE}")
|
37
|
+
nodes_in_template.each do | node_in_template |
|
38
|
+
define_reader_for node_in_template
|
39
|
+
@nodes_paths = @nodes_paths.merge ({ node_in_template.text.to_sym => node_in_template.path })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def define_reader_for node_in_template
|
44
|
+
attr_value = @xml.xpath(remove_spec_node_from(node_in_template.path)).text
|
45
|
+
self.class.add_attr_reader_for node_in_template, attr_value
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.add_attr_reader_for node_in_template, attr_value
|
49
|
+
define_method node_in_template.text.to_sym, lambda { attr_value }
|
50
|
+
end
|
51
|
+
|
52
|
+
def remove_spec_node_from a_path
|
53
|
+
a_path.gsub("/#{SPEC_NODE}", "")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/match_point.rb
CHANGED
data/spec/match_point_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MatchPoint do
|
4
4
|
|
5
|
-
describe("when reading the bxml
|
5
|
+
describe("when reading the bxml template") do
|
6
6
|
|
7
|
-
let(:
|
7
|
+
let(:template) do
|
8
8
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
|
9
9
|
<TIX version=\"TIX 4.11.0\">
|
10
10
|
<AccessControl method=\"AccessControlAuthenticate\">
|
@@ -26,12 +26,25 @@ describe MatchPoint do
|
|
26
26
|
</TIX>"
|
27
27
|
end
|
28
28
|
|
29
|
-
let(:response) { MatchPoint::
|
29
|
+
let(:response) { MatchPoint::XmlInstance.new(template, response_xml) }
|
30
|
+
let(:request) { MatchPoint::XmlInstance.new(template, response_xml, {:auth_id=>"NeWVaLue"})}
|
30
31
|
|
31
|
-
it "should get the auth_id from the xml if the
|
32
|
+
it "should get the auth_id from the xml if the template for that field is defined" do
|
32
33
|
response.auth_id.should == "1ua5J1gJz3TryPEMQZkeWFarOagSJvYY"
|
33
34
|
end
|
34
35
|
|
36
|
+
it "should create an xml with the values on the hash" do
|
37
|
+
request.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
38
|
+
<TIX version=\"TIX 4.11.0\">
|
39
|
+
<AccessControl method=\"AccessControlAuthenticate\">
|
40
|
+
<AuthRequest>
|
41
|
+
<AuthID>NeWVaLue</AuthID>
|
42
|
+
</AuthRequest>
|
43
|
+
</AccessControl>
|
44
|
+
</TIX>
|
45
|
+
"
|
46
|
+
end
|
47
|
+
|
35
48
|
end
|
36
49
|
|
37
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: match_point
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -51,12 +51,10 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- lib/match_point.rb
|
54
|
-
- lib/match_point/
|
55
|
-
- lib/match_point/some_class.rb
|
54
|
+
- lib/match_point/xml_instance.rb
|
56
55
|
- lib/match_point/version.rb
|
57
56
|
- spec/spec_helper.rb
|
58
57
|
- spec/match_point_spec.rb
|
59
|
-
- test/test_match_point.rb
|
60
58
|
homepage: ''
|
61
59
|
licenses: []
|
62
60
|
post_install_message:
|
@@ -84,4 +82,3 @@ summary: ''
|
|
84
82
|
test_files:
|
85
83
|
- spec/spec_helper.rb
|
86
84
|
- spec/match_point_spec.rb
|
87
|
-
- test/test_match_point.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module MatchPoint
|
2
|
-
class BxmlResponse
|
3
|
-
|
4
|
-
SPEC_NODE="MatchPointSpec"
|
5
|
-
|
6
|
-
def initialize xml_specification, xml
|
7
|
-
@specification = Nokogiri::XML(xml_specification)
|
8
|
-
@xml = Nokogiri::XML(xml)
|
9
|
-
|
10
|
-
self.define_methods
|
11
|
-
end
|
12
|
-
|
13
|
-
def define_methods
|
14
|
-
specified_nodes = @specification.xpath("//#{SPEC_NODE}")
|
15
|
-
specified_nodes.each do | specification_node |
|
16
|
-
attr_value = @xml.xpath(specification_node.path.gsub("/#{SPEC_NODE}","")).text
|
17
|
-
self.class.add_attr_reader_for specification_node, attr_value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.add_attr_reader_for specification_node, attr_value
|
22
|
-
define_method specification_node.text.to_sym, lambda { attr_value }
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|