om 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.textile +4 -0
- data/VERSION +1 -1
- data/lib/om/xml/accessors.rb +7 -9
- data/om.gemspec +1 -1
- data/spec/unit/accessors_spec.rb +8 -7
- metadata +3 -3
data/History.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/om/xml/accessors.rb
CHANGED
@@ -92,12 +92,8 @@ module OM::XML::Accessors
|
|
92
92
|
end
|
93
93
|
else
|
94
94
|
|
95
|
-
# if indices[key_index]
|
96
|
-
# add_position_predicate!(relative_path, indices[key_index])
|
97
|
-
# end
|
98
|
-
|
99
95
|
unless index.nil?
|
100
|
-
add_position_predicate
|
96
|
+
relative_path = add_position_predicate(relative_path, index)
|
101
97
|
end
|
102
98
|
|
103
99
|
if accessor_info.has_key?(:default_content_path)
|
@@ -106,7 +102,7 @@ module OM::XML::Accessors
|
|
106
102
|
|
107
103
|
end
|
108
104
|
if pointer_index > 0
|
109
|
-
relative_path
|
105
|
+
relative_path = "/"+relative_path
|
110
106
|
end
|
111
107
|
xpath << relative_path
|
112
108
|
end
|
@@ -114,14 +110,16 @@ module OM::XML::Accessors
|
|
114
110
|
return xpath
|
115
111
|
end
|
116
112
|
|
117
|
-
def add_position_predicate
|
113
|
+
def add_position_predicate(xpath_query, array_index_value)
|
114
|
+
modified_query = xpath_query.dup
|
118
115
|
position_function = "position()=#{array_index_value + 1}"
|
119
116
|
|
120
117
|
if xpath_query.include?("]")
|
121
|
-
|
118
|
+
modified_query.insert(xpath_query.rindex("]"), " and #{position_function}")
|
122
119
|
else
|
123
|
-
|
120
|
+
modified_query << "[#{position_function}]"
|
124
121
|
end
|
122
|
+
return modified_query
|
125
123
|
end
|
126
124
|
|
127
125
|
def accessor_generic_name(*pointers)
|
data/om.gemspec
CHANGED
data/spec/unit/accessors_spec.rb
CHANGED
@@ -116,10 +116,7 @@ describe "OM::XML::Accessors" do
|
|
116
116
|
it "should return the xpath given in the call to #accessor" do
|
117
117
|
AccessorTest.accessor_info( :abstract ).should == AccessorTest.accessors[:abstract]
|
118
118
|
end
|
119
|
-
it "should dig into the accessors hash as far as you want, ignoring index values" do
|
120
|
-
# Old Syntax ...
|
121
|
-
# AccessorTest.accessor_info( :conference, 0, :role, 1, :text ).should == AccessorTest.accessors[:conference][:children][:role][:children][:text]
|
122
|
-
|
119
|
+
it "should dig into the accessors hash as far as you want, ignoring index values" do
|
123
120
|
AccessorTest.accessor_info( *[{:conference=>0}, {:role=>1}, :text] ).should == AccessorTest.accessors[:conference][:children][:role][:children][:text]
|
124
121
|
AccessorTest.accessor_info( {:conference=>0}, {:role=>1}, :text ).should == AccessorTest.accessors[:conference][:children][:role][:children][:text]
|
125
122
|
|
@@ -133,22 +130,26 @@ describe "OM::XML::Accessors" do
|
|
133
130
|
end
|
134
131
|
# Note: Ruby array indexes begin from 0. In xpath queries (which start from 1 instead of 0), this will be translated accordingly.
|
135
132
|
it "should prepend the xpath for any parent nodes, inserting calls to xpath:position() function where necessary" do
|
136
|
-
# Old Syntax ...
|
137
|
-
# AccessorTest.accessor_xpath( :conference, 0, :role, 1, :text ).should == '//oxns:name[@type="conference" and position()=1]/oxns:role[position()=2]/oxns:roleTerm[@type="text"]'
|
138
|
-
|
139
133
|
AccessorTest.accessor_xpath( {:conference=>0}, {:role=>1}, :text ).should == '//oxns:name[@type="conference" and position()=1]/oxns:role[position()=2]/oxns:roleTerm[@type="text"]'
|
140
134
|
end
|
135
|
+
it "should be idempotent" do
|
136
|
+
AccessorTest.accessor_xpath( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[position()=3]/oxns:title"
|
137
|
+
AccessorTest.accessor_xpath( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[position()=3]/oxns:title"
|
138
|
+
AccessorTest.accessor_xpath( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[position()=3]/oxns:title"
|
139
|
+
end
|
141
140
|
end
|
142
141
|
|
143
142
|
describe "#accessor_generic_name" do
|
144
143
|
it "should generate a generic accessor name based on an array of pointers" do
|
145
144
|
AccessorTest.accessor_generic_name( {:conference=>0}, {:role=>1}, :text ).should == "conference_role_text"
|
145
|
+
AccessorTest.accessor_generic_name( *[{:conference=>0}, {:role=>1}, :text] ).should == "conference_role_text"
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
149
|
describe "#accessor_hierarchical_name" do
|
150
150
|
it "should generate a specific accessor name based on an array of pointers and indexes" do
|
151
151
|
AccessorTest.accessor_hierarchical_name( {:conference=>0}, {:role=>1}, :text ).should == "conference_0_role_1_text"
|
152
|
+
AccessorTest.accessor_hierarchical_name( *[{:conference=>0}, {:role=>1}, :text] ).should == "conference_0_role_1_text"
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: om
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zumwalt
|