om 1.2.5 → 1.3.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.
- data/COMMON_OM_PATTERNS.textile +127 -0
- data/GETTING_FANCY.textile +15 -13
- data/GETTING_STARTED.textile +89 -51
- data/QUERYING_DOCUMENTS.textile +30 -25
- data/README.rdoc +5 -1
- data/README.textile +4 -0
- data/lib/om/samples/mods_article.rb +7 -4
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/document.rb +10 -2
- data/lib/om/xml/named_term_proxy.rb +7 -2
- data/lib/om/xml/term.rb +59 -9
- data/lib/om/xml/term_value_operators.rb +3 -0
- data/lib/om/xml/terminology.rb +29 -0
- data/lib/om/xml.rb +3 -0
- data/spec/fixtures/mods_article_terminology.xml +2882 -0
- data/spec/unit/document_spec.rb +12 -0
- data/spec/unit/named_term_proxy_spec.rb +22 -9
- data/spec/unit/term_builder_spec.rb +1 -1
- data/spec/unit/term_spec.rb +20 -3
- data/spec/unit/term_value_operators_spec.rb +24 -0
- data/spec/unit/terminology_spec.rb +5 -5
- data/spec/unit/xml_serialization_spec.rb +63 -0
- metadata +12 -8
- data/VERSION +0 -1
data/spec/unit/document_spec.rb
CHANGED
@@ -147,5 +147,17 @@ describe "OM::XML::Document" do
|
|
147
147
|
@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.should == "FAMILY NAME"
|
148
148
|
end
|
149
149
|
end
|
150
|
+
|
151
|
+
describe "node_exists?" do
|
152
|
+
it "should return true if any nodes are found" do
|
153
|
+
@mods_article.node_exists?( {:person=>1}, :first_name).should be_true
|
154
|
+
end
|
155
|
+
it "should return false if no nodes are found" do
|
156
|
+
@mods_article.node_exists?( {:person=>8}, :first_name ).should be_false
|
157
|
+
end
|
158
|
+
it "should support xpath queries" do
|
159
|
+
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').should be_true
|
160
|
+
end
|
161
|
+
end
|
150
162
|
|
151
163
|
end
|
@@ -5,21 +5,29 @@ describe "OM::XML::NamedTermProxy" do
|
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class NamedProxyTestDocument
|
9
|
+
include OM::XML::Document
|
10
|
+
set_terminology do |t|
|
11
|
+
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
|
12
|
+
t.parent {
|
13
|
+
t.foo {
|
14
|
+
t.bar
|
15
|
+
}
|
16
|
+
t.my_proxy(:proxy=>[:foo, :bar])
|
12
17
|
}
|
13
|
-
t.
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
t.adoptive_parent(:ref=>[:parent], :attributes=>{:type=>"adoptive"})
|
19
|
+
t.parentfoobarproxy(:proxy=>[:parent, :foo, :bar])
|
20
|
+
end
|
21
|
+
def self.xml_template
|
22
|
+
'<mods xmlns="http://www.loc.gov/mods/v3"><parent><foo/></parent></mods>'
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
|
-
@test_terminology =
|
26
|
+
@test_terminology = NamedProxyTestDocument.terminology
|
20
27
|
@test_proxy = @test_terminology.retrieve_term(:parent, :my_proxy)
|
21
28
|
@proxied_term = @test_terminology.retrieve_term(:parent, :foo, :bar)
|
22
29
|
@adoptive_parent = @test_terminology.retrieve_term(:adoptive_parent)
|
30
|
+
|
23
31
|
end
|
24
32
|
|
25
33
|
it "should proxy all extra methods to the proxied object" do
|
@@ -40,4 +48,9 @@ describe "OM::XML::NamedTermProxy" do
|
|
40
48
|
it "should support NamedTermProxies that point to root terms" do
|
41
49
|
@test_terminology.xpath_for(:parentfoobarproxy).should == "//oxns:parent/oxns:foo/oxns:bar"
|
42
50
|
end
|
51
|
+
it "should be usable in update_values" do
|
52
|
+
document = NamedProxyTestDocument.from_xml(NamedProxyTestDocument.xml_template)
|
53
|
+
document.update_values([:parentfoobarproxy] => "FOObar!")
|
54
|
+
document.term_values(:parentfoobarproxy).should == ["FOObar!"]
|
55
|
+
end
|
43
56
|
end
|
@@ -142,7 +142,7 @@ describe "OM::XML::Term::Builder" do
|
|
142
142
|
end
|
143
143
|
it "should raise an error if the referece points to a nonexistent term builder" do
|
144
144
|
tb = OM::XML::Term::Builder.new("mork",@test_terminology_builder).ref(:characters, :aliens)
|
145
|
-
lambda { tb.lookup_refs }.should raise_error(OM::XML::Terminology::BadPointerError,"
|
145
|
+
lambda { tb.lookup_refs }.should raise_error(OM::XML::Terminology::BadPointerError,"This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \":characters\"")
|
146
146
|
end
|
147
147
|
it "should raise an error with informative error when given circular references" do
|
148
148
|
lambda { @pineapple.lookup_refs }.should raise_error(OM::XML::Terminology::CircularReferenceError,"Circular reference in Terminology: :pineapple => :banana => :coconut => :pineapple")
|
data/spec/unit/term_spec.rb
CHANGED
@@ -163,16 +163,33 @@ describe "OM::XML::Term" do
|
|
163
163
|
describe "#xml_builder_template" do
|
164
164
|
|
165
165
|
it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
|
166
|
-
@test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\',
|
166
|
+
@test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
|
167
167
|
@test_affiliation.xml_builder_template.should == 'xml.affiliation( \'#{builder_new_value}\' )'
|
168
168
|
end
|
169
169
|
it "should accept extra options" do
|
170
|
-
marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\',
|
170
|
+
marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', \'type\'=>\'code\', \'authority\'=>\'marcrelator\' )'
|
171
171
|
@test_role_code.xml_builder_template(:attributes=>{"authority"=>"marcrelator"}).should == marcrelator_role_xml_builder_template
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should work for nodes with default_content_path" do
|
175
|
-
@test_volume.xml_builder_template.should == "xml.detail(
|
175
|
+
@test_volume.xml_builder_template.should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should support terms that are attributes" do
|
179
|
+
pending "HYDRA-415"
|
180
|
+
@type_attribute_term = OM::XML::Term.new(:type_attribute, :path=>{:attribute=>:type})
|
181
|
+
@type_attribute_term.xml_builder_template.should == "TODO!"
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should support terms with namespaced attributes" do
|
185
|
+
@french_title = OM::XML::Term.new(:french_title, :path=>"title", :attributes=>{"xml:lang"=>"fre"})
|
186
|
+
@french_title.xml_builder_template.should == "xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should support terms that are namespaced attributes" do
|
190
|
+
pending "HYDRA-415"
|
191
|
+
@xml_lang_attribute_term = OM::XML::Term.new(:xml_lang_attribute, :path=>{:attribute=>"xml:lang"})
|
192
|
+
@xml_lang_attribute_term.xml_builder_template.should == "TODO!"
|
176
193
|
end
|
177
194
|
|
178
195
|
end
|
@@ -6,6 +6,7 @@ describe "OM::XML::TermValueOperators" do
|
|
6
6
|
before(:each) do
|
7
7
|
@sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
|
8
8
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
9
|
+
@empty_sample = OM::Samples::ModsArticle.from_xml("")
|
9
10
|
end
|
10
11
|
|
11
12
|
describe ".term_values" do
|
@@ -113,6 +114,23 @@ describe "OM::XML::TermValueOperators" do
|
|
113
114
|
@article.term_values(:person, :description).should include(" 'phrul gyi lde mig")
|
114
115
|
end
|
115
116
|
|
117
|
+
it "should support inserting nodes with namespaced attributes" do
|
118
|
+
@sample.update_values({['title_info', 'french_title']=>'Le Titre'})
|
119
|
+
@sample.term_values('title_info', 'french_title').should == ['Le Titre']
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should support inserting attributes" do
|
123
|
+
pending "HYDRA-415"
|
124
|
+
@sample.update_values({['title_info', 'language']=>'Le Titre'})
|
125
|
+
@sample.term_values('title_info', 'french_title').should == ['Le Titre']
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should support inserting namespaced attributes" do
|
129
|
+
pending "HYDRA-415"
|
130
|
+
@sample.update_values({['title_info', 'main_title', 'main_title_lang']=>'eng'})
|
131
|
+
@sample.term_values('title_info', 'main_title', 'main_title_lang').should == ['eng']
|
132
|
+
end
|
133
|
+
|
116
134
|
### Examples copied over form nokogiri_datastream_spec
|
117
135
|
|
118
136
|
it "should apply submitted hash to corresponding datastream field values" do
|
@@ -422,4 +440,10 @@ describe "OM::XML::TermValueOperators" do
|
|
422
440
|
end
|
423
441
|
end
|
424
442
|
|
443
|
+
describe "build_ancestors" do
|
444
|
+
it "should raise an error if it cant find a starting point for building from" do
|
445
|
+
lambda { @empty_sample.build_ancestors( [:journal, :issue], 0) }.should raise_error(OM::XML::TemplateMissingException, "Cannot insert nodes into the document because it is empty.")
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
425
449
|
end
|
@@ -279,19 +279,19 @@ describe "OM::XML::Terminology" do
|
|
279
279
|
describe "#xml_builder_template" do
|
280
280
|
|
281
281
|
it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
|
282
|
-
@test_full_terminology.xml_builder_template(:person,:date).should == 'xml.namePart( \'#{builder_new_value}\',
|
282
|
+
@test_full_terminology.xml_builder_template(:person,:date).should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
|
283
283
|
@test_full_terminology.xml_builder_template(:name,:affiliation).should == 'xml.affiliation( \'#{builder_new_value}\' )'
|
284
284
|
end
|
285
285
|
it "should accept extra options" do
|
286
|
-
marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\',
|
286
|
+
marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', \'type\'=>\'code\', \'authority\'=>\'marcrelator\' )'
|
287
287
|
@test_full_terminology.xml_builder_template(:role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
|
288
288
|
@test_full_terminology.xml_builder_template(:person, :role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
|
289
289
|
end
|
290
290
|
|
291
291
|
it "should work with deeply nested properties" do
|
292
|
-
@test_full_terminology.xml_builder_template(:issue, :volume).should == "xml.detail(
|
293
|
-
@test_full_terminology.xml_builder_template(:journal, :issue, :level).should == "xml.detail(
|
294
|
-
@test_full_terminology.xml_builder_template(:journal, :issue, :volume).should == "xml.detail(
|
292
|
+
@test_full_terminology.xml_builder_template(:issue, :volume).should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
|
293
|
+
@test_full_terminology.xml_builder_template(:journal, :issue, :level).should == "xml.detail( \'type\'=>'number' ) { xml.number( '\#{builder_new_value}' ) }"
|
294
|
+
@test_full_terminology.xml_builder_template(:journal, :issue, :volume).should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
|
295
295
|
@test_full_terminology.xml_builder_template(:journal, :issue, :pages, :start).should == "xml.start( '\#{builder_new_value}' )"
|
296
296
|
end
|
297
297
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require "om"
|
3
|
+
require "om/samples"
|
4
|
+
|
5
|
+
describe "OM::XML::Terminology.to_xml" do
|
6
|
+
before(:all) do
|
7
|
+
@terminology = OM::Samples::ModsArticle.terminology
|
8
|
+
end
|
9
|
+
it "should put terminology details into the xml" do
|
10
|
+
expected_xml = "<namespaces>\n <namespace>\n <name>oxns</name>\n <identifier>http://www.loc.gov/mods/v3</identifier>\n </namespace>\n <namespace>\n <name>xmlns:foo</name>\n <identifier>http://my.custom.namespace</identifier>\n </namespace>\n <namespace>\n <name>xmlns</name>\n <identifier>http://www.loc.gov/mods/v3</identifier>\n </namespace>\n</namespaces>"
|
11
|
+
xml = @terminology.to_xml
|
12
|
+
xml.xpath("/terminology/schema").to_xml.should == "<schema>http://www.loc.gov/standards/mods/v3/mods-3-2.xsd</schema>"
|
13
|
+
xml.xpath("/terminology/namespaces").to_xml.should be_equivalent_to expected_xml
|
14
|
+
# file = File.open(File.dirname(__FILE__)+"/../fixtures/mods_article_terminology.xml", "w")
|
15
|
+
# file.write(xml.to_xml)
|
16
|
+
end
|
17
|
+
it "should call .to_xml on all of the terms" do
|
18
|
+
options = {}
|
19
|
+
doc = Nokogiri::XML::Document.new
|
20
|
+
@terminology.terms.values.each {|term| term.expects(:to_xml) }
|
21
|
+
@terminology.to_xml(options,doc)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
describe "OM::XML::Term.to_xml" do
|
27
|
+
before(:all) do
|
28
|
+
@terminology = OM::Samples::ModsArticle.terminology
|
29
|
+
@person = @terminology.retrieve_term(:person)
|
30
|
+
@person_first_name = @terminology.retrieve_term(:person, :first_name)
|
31
|
+
end
|
32
|
+
it "should return an xml representation of the Term" do
|
33
|
+
xml = @person_first_name.to_xml
|
34
|
+
xml.xpath("/term").first.attributes["name"].value.should == "first_name"
|
35
|
+
xml.xpath("/term/attributes/type").first.text.should == "given"
|
36
|
+
xml.xpath("/term/path").first.text.should == "namePart"
|
37
|
+
xml.xpath("/term/namespace_prefix").first.text.should == "oxns"
|
38
|
+
xml.xpath("/term/children/*").should be_empty
|
39
|
+
xml.xpath("/term/xpath/relative").first.text.should == "oxns:namePart[@type=\"given\"]"
|
40
|
+
xml.xpath("/term/xpath/absolute").first.text.should == "//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"given\"]"
|
41
|
+
xml.xpath("/term/xpath/constrained").first.text.should == "//oxns:name[@type=\\\"personal\\\"]/oxns:namePart[@type=\\\"given\\\" and contains(., \\\"\#{constraint_value}\\\")]"
|
42
|
+
xml.xpath("/term/index_as").first.text.should == ""
|
43
|
+
xml.xpath("/term/required").first.text.should == "false"
|
44
|
+
xml.xpath("/term/data_type").first.text.should == "string"
|
45
|
+
end
|
46
|
+
it "should capture root term info" do
|
47
|
+
xml = @terminology.root_terms.first.to_xml
|
48
|
+
xml.xpath("/term/is_root_term").text.should == "true"
|
49
|
+
@person_first_name.to_xml.xpath("/term/is_root_term").should be_empty
|
50
|
+
end
|
51
|
+
it "should allow you to pass in a document to add the term to" do
|
52
|
+
doc = Nokogiri::XML::Document.new
|
53
|
+
@person_first_name.to_xml({}, doc).should == doc
|
54
|
+
end
|
55
|
+
it "should include children" do
|
56
|
+
children = @person.to_xml.xpath("//term[@name=\"person\"]/children/*")
|
57
|
+
children.length.should == 12
|
58
|
+
children.each {|child| child.name.should == "term"}
|
59
|
+
end
|
60
|
+
it "should skip children if :children=>false" do
|
61
|
+
@person.to_xml(:children=>false).xpath("children").should be_empty
|
62
|
+
end
|
63
|
+
end
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zumwalt
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-26 00:00:00 -05:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: nokogiri
|
@@ -121,7 +122,6 @@ files:
|
|
121
122
|
- README.textile
|
122
123
|
- Rakefile
|
123
124
|
- UPDATING_DOCUMENTS.textile
|
124
|
-
- VERSION
|
125
125
|
- container_spec.rb
|
126
126
|
- lib/om.rb
|
127
127
|
- lib/om/samples.rb
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- spec/fixtures/CBF_MODS/ARS0025_016.xml
|
146
146
|
- spec/fixtures/RUBRIC_mods_article_template.xml
|
147
147
|
- spec/fixtures/mods-3-2.xsd
|
148
|
+
- spec/fixtures/mods_article_terminology.xml
|
148
149
|
- spec/fixtures/mods_articles/hydrangea_article1.xml
|
149
150
|
- spec/fixtures/test_dummy_mods.xml
|
150
151
|
- spec/integration/rights_metadata_integration_example_spec.rb
|
@@ -164,7 +165,9 @@ files:
|
|
164
165
|
- spec/unit/terminology_builder_spec.rb
|
165
166
|
- spec/unit/terminology_spec.rb
|
166
167
|
- spec/unit/validation_spec.rb
|
168
|
+
- spec/unit/xml_serialization_spec.rb
|
167
169
|
- spec/unit/xml_spec.rb
|
170
|
+
has_rdoc: true
|
168
171
|
homepage: http://github.com/mediashelf/om
|
169
172
|
licenses: []
|
170
173
|
|
@@ -194,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
197
|
requirements: []
|
195
198
|
|
196
199
|
rubyforge_project:
|
197
|
-
rubygems_version: 1.
|
200
|
+
rubygems_version: 1.6.2
|
198
201
|
signing_key:
|
199
202
|
specification_version: 3
|
200
203
|
summary: "OM (Opinionated Metadata): A library to help you tame sprawling XML schemas like MODS."
|
@@ -202,6 +205,7 @@ test_files:
|
|
202
205
|
- spec/fixtures/CBF_MODS/ARS0025_016.xml
|
203
206
|
- spec/fixtures/RUBRIC_mods_article_template.xml
|
204
207
|
- spec/fixtures/mods-3-2.xsd
|
208
|
+
- spec/fixtures/mods_article_terminology.xml
|
205
209
|
- spec/fixtures/mods_articles/hydrangea_article1.xml
|
206
210
|
- spec/fixtures/test_dummy_mods.xml
|
207
211
|
- spec/integration/rights_metadata_integration_example_spec.rb
|
@@ -221,5 +225,5 @@ test_files:
|
|
221
225
|
- spec/unit/terminology_builder_spec.rb
|
222
226
|
- spec/unit/terminology_spec.rb
|
223
227
|
- spec/unit/validation_spec.rb
|
228
|
+
- spec/unit/xml_serialization_spec.rb
|
224
229
|
- spec/unit/xml_spec.rb
|
225
|
-
has_rdoc:
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.2.4
|