om 0.1.9 → 0.1.10
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 +15 -5
- data/om.gemspec +2 -2
- data/spec/unit/accessors_spec.rb +8 -0
- data/spec/unit/properties_spec.rb +9 -4
- metadata +4 -4
data/History.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/lib/om/xml/accessors.rb
CHANGED
@@ -140,6 +140,12 @@ module OM::XML::Accessors
|
|
140
140
|
return xpath
|
141
141
|
end
|
142
142
|
|
143
|
+
def accessor_constrained_xpath(pointers, constraint)
|
144
|
+
constraint_function = "contains(., \"#{constraint}\")"
|
145
|
+
xpath = self.accessor_xpath(*pointers)
|
146
|
+
xpath = self.add_predicate(xpath, constraint_function)
|
147
|
+
end
|
148
|
+
|
143
149
|
# Adds xpath xpath node index predicate to the end of your xpath query
|
144
150
|
# Example:
|
145
151
|
# add_node_index_predicate("//oxns:titleInfo",0)
|
@@ -161,13 +167,17 @@ module OM::XML::Accessors
|
|
161
167
|
# add_position_predicate("//oxns:titleInfo[@lang=\"finnish\"]",0)
|
162
168
|
# => "//oxns:titleInfo[@lang=\"finnish\" and position()=1]"
|
163
169
|
def add_position_predicate(xpath_query, array_index_value)
|
164
|
-
modified_query = xpath_query.dup
|
165
170
|
position_function = "position()=#{array_index_value + 1}"
|
166
|
-
|
167
|
-
|
168
|
-
|
171
|
+
self.add_predicate(xpath_query, position_function)
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_predicate(xpath_query, predicate)
|
175
|
+
modified_query = xpath_query.dup
|
176
|
+
# if xpath_query.include?("]")
|
177
|
+
if xpath_query[xpath_query.length-1..xpath_query.length] == "]"
|
178
|
+
modified_query.insert(xpath_query.rindex("]"), " and #{predicate}")
|
169
179
|
else
|
170
|
-
modified_query << "[#{
|
180
|
+
modified_query << "[#{predicate}]"
|
171
181
|
end
|
172
182
|
return modified_query
|
173
183
|
end
|
data/om.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{om}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Zumwalt"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-06}
|
13
13
|
s.description = %q{OM (Opinionated Metadata): A library to help you tame sprawling XML schemas like MODS. Wraps Nokogiri documents in objects with miscellaneous helper methods for doing things like retrieve generated xpath queries or look up properties based on a simplified DSL}
|
14
14
|
s.email = %q{matt.zumwalt@yourmediashelf.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/unit/accessors_spec.rb
CHANGED
@@ -146,6 +146,14 @@ describe "OM::XML::Accessors" do
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
+
describe "#accessor_constrained_xpath" do
|
150
|
+
it 'should append contains("#{constraint_value}") to query' do
|
151
|
+
# @sample.class.accessor_constrained_xpath_template([:journal, :issn]).should == '//oxns:relatedItem[@type="host"]/oxns:identifier[@type="issn" and contains("#{constraint_value}")]'
|
152
|
+
@sample.class.accessor_constrained_xpath([:journal, :issn], "123-456-ABC").should == '//oxns:relatedItem[@type="host"]/oxns:identifier[@type="issn" and contains(., "123-456-ABC")]'
|
153
|
+
@sample.class.accessor_constrained_xpath([:journal, :title], "My Journal Title").should == '//oxns:relatedItem[@type="host"]/oxns:titleInfo/oxns:title[contains(., "My Journal Title")]'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
149
157
|
describe "#accessor_generic_name" do
|
150
158
|
it "should generate a generic accessor name based on an array of pointers" do
|
151
159
|
AccessorTest.accessor_generic_name( {:conference=>0}, {:role=>1}, :text ).should == "conference_role_text"
|
@@ -202,11 +202,11 @@ describe "OM::XML::Properties" do
|
|
202
202
|
@fixturemods.ng_xml.expects(:xpath).with('//oxns:name[@type="personal" and contains(oxns:role/oxns:roleTerm, "donor")]', @fixturemods.ox_namespaces)
|
203
203
|
@fixturemods.lookup(:person, :role=>"donor")
|
204
204
|
|
205
|
-
#
|
206
|
-
#
|
205
|
+
#
|
206
|
+
# This is the way we want to move towards... (currently implementing part of this in accessor_constrained_xpath)
|
207
|
+
# @fixturemods.ng_xml.expects(:xpath).with('//oxns:relatedItem/oxns:identifier[@type=\'issn\'] and contains("123-ABC-44567")]', @fixturemods.ox_namespaces)
|
208
|
+
# @fixturemods.lookup([:journal, :issn], "123-ABC-44567")
|
207
209
|
|
208
|
-
# @fixturemods.expects(:xpath).with('//oxns:name[contains(oxns:namePart[@type="date"], "2010")]', @fixturemods.ox_namespaces)
|
209
|
-
# @fixturemods.lookup([:person,:date], "2010")
|
210
210
|
end
|
211
211
|
|
212
212
|
end
|
@@ -254,8 +254,13 @@ describe "OM::XML::Properties" do
|
|
254
254
|
FakeOxMods.generate_xpath(opts1, :variations=>{:attributes=>{:type=>"personal"}, :subelement_path=>["role", "roleTerm"] } ).should == '//oxns:name[@type="personal"]/oxns:role/oxns:roleTerm'
|
255
255
|
|
256
256
|
FakeOxMods.generate_xpath( opts3, :variations=>{:attributes=>{:type=>"date"}} ).should == '//oxns:name/oxns:namePart[@type="date"]'
|
257
|
+
FakeOxMods.generate_xpath( opts3, :variations=>{:attributes=>{:type=>"date"}}, :constraints=>:default ).should == '//oxns:name/oxns:namePart[@type="date" and contains("#{constraint_value}")]'
|
258
|
+
|
259
|
+
FakeOxMods.generate_xpath( {:path=>["relatedItem", "identifier"]}, :variations=>{:attributes=>{:type=>"issn"}}, :constraints=>:default ).should == '//oxns:relatedItem/oxns:identifier[@type="issn" and contains("#{constraint_value}")]'
|
260
|
+
|
257
261
|
end
|
258
262
|
|
263
|
+
|
259
264
|
it "should support relative paths" do
|
260
265
|
relative_opts = {:path=>"namePart"}
|
261
266
|
FakeOxMods.generate_xpath( relative_opts, :variations=>{:attributes=>{:type=>"date"}}, :relative=>true).should == 'oxns:namePart[@type="date"]'
|
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: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 10
|
10
|
+
version: 0.1.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zumwalt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-06 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|