om 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -133,11 +133,20 @@ module OM::XML::Properties
133
133
  prefix = "oxns"
134
134
  property_info[:path] ||= ""
135
135
  path = property_info[:path]
136
- path_array = Array( path )
136
+ unless path.kind_of?(Hash)
137
+ path = Array( path )
138
+ end
137
139
  template = ""
138
140
  template << "//" unless opts[:relative]
139
141
  template << "#{prefix}:"
140
- template << delimited_list(path_array, "/#{prefix}:")
142
+
143
+ if path.kind_of?(Hash)
144
+ if path.has_key?(:attribute)
145
+ template = "@"+path[:attribute]
146
+ end
147
+ else
148
+ template << delimited_list(path, "/#{prefix}:")
149
+ end
141
150
 
142
151
  predicates = []
143
152
  default_content_path = property_info.has_key?(:default_content_path) ? property_info[:default_content_path] : ""
@@ -175,13 +184,18 @@ module OM::XML::Properties
175
184
  end
176
185
  elsif opts[:constraints].has_key?(:path)
177
186
  constraint_predicates = []
178
- if opts.has_key?(:subelement_of)
179
- constraint_path = "#{prefix}:#{opts[:constraints][:path]}"
180
- if opts[:constraints].has_key?(:default_content_path)
181
- constraint_path << "/#{prefix}:#{opts[:constraints][:default_content_path]}"
182
- end
187
+
188
+ constraints_path_arg = opts[:constraints][:path]
189
+ if constraints_path_arg.kind_of?(Hash)
190
+ if constraints_path_arg.has_key?(:attribute)
191
+ constraint_path = "@"+constraints_path_arg[:attribute]
192
+ end
183
193
  else
184
- constraint_path = "#{prefix}:#{opts[:constraints][:path]}"
194
+ constraint_path = "#{prefix}:#{constraints_path_arg}"
195
+ end
196
+ if opts.has_key?(:subelement_of) && opts[:constraints].has_key?(:default_content_path)
197
+ # constraint_path = "#{prefix}:#{opts[:constraints][:path]}"
198
+ constraint_path << "/#{prefix}:#{opts[:constraints][:default_content_path]}"
185
199
  end
186
200
  arguments_for_contains_function << constraint_path
187
201
 
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.6"
8
+ s.version = "0.1.7"
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-06-30}
12
+ s.date = %q{2010-07-02}
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 = [
@@ -167,9 +167,8 @@ describe "OM::XML::Accessors" do
167
167
  end
168
168
 
169
169
  it "should generate accessors from the properties hash" do
170
- sample_properties_hash = {:mods=>{:path=>"mods", :attributes=>["id", "version"], :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd", :ref=>:mods, :xpath_relative=>"oxns:mods", :xpath_constrained=>"//oxns:mods[contains(\\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:mods", :convenience_methods=>{}}, :person=>{:path=>"name", :attributes=>{:type=>"personal"}, :subelements=>["namePart", "displayForm", "affiliation", :role, "description"], :ref=>:person, :xpath_relative=>"oxns:name[@type=\"personal\"]", :variant_of=>:name_, :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :default_content_path=>"namePart", :xpath=>"//oxns:name[@type=\"personal\"]", :convenience_methods=>{:first_name=>{:path=>"namePart", :attributes=>{:type=>"given"}, :xpath_relative=>"oxns:namePart[@type=\"given\"]", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"given\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"given\"]"}, :affiliation=>{:path=>"affiliation", :xpath_relative=>"oxns:affiliation", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:affiliation, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:affiliation"}, :terms_of_address=>{:path=>"namePart", :attributes=>{:type=>"termsOfAddress"}, :xpath_relative=>"oxns:namePart[@type=\"termsOfAddress\"]", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"termsOfAddress\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"termsOfAddress\"]"}, :namePart=>{:path=>"namePart", :xpath_relative=>"oxns:namePart", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart"}, :role=>{:path=>"role", :attributes=>[{"type"=>["text", "code"]}, "authority"], :ref=>:role, :xpath_relative=>"oxns:role", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:role, \\\"\#{constraint_value}\\\")]", :parents=>[:name_], :convenience_methods=>{:text=>{:path=>"roleTerm", :attributes=>{:type=>"text"}, :xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:path=>"roleTerm", :attributes=>{:type=>"code"}, :xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}, :xpath=>"//oxns:name[@type=\"personal\"]/oxns:role"}, :displayForm=>{:path=>"displayForm", :xpath_relative=>"oxns:displayForm", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:displayForm, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:displayForm"}, :date=>{:path=>"namePart", :attributes=>{:type=>"date"}, :xpath_relative=>"oxns:namePart[@type=\"date\"]", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"date\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"date\"]"}, :family_name=>{:path=>"namePart", :attributes=>{:type=>"family"}, :xpath_relative=>"oxns:namePart[@type=\"family\"]", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"family\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"family\"]"}, :description=>{:path=>"description", :xpath_relative=>"oxns:description", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:description, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:description"}}}, :name_=>{:path=>"name", :attributes=>[:xlink, :lang, "xml:lang", :script, :transliteration, {:type=>["personal", "enumerated", "corporate"]}], :subelements=>["namePart", "displayForm", "affiliation", :role, "description"], :ref=>:name_, :xpath_relative=>"oxns:name", :xpath_constrained=>"//oxns:name[contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :default_content_path=>"namePart", :xpath=>"//oxns:name", :convenience_methods=>{:first_name=>{:path=>"namePart", :attributes=>{:type=>"given"}, :xpath_relative=>"oxns:namePart[@type=\"given\"]", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"given\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart[@type=\"given\"]"}, :affiliation=>{:path=>"affiliation", :xpath_relative=>"oxns:affiliation", :xpath_constrained=>"//oxns:name[contains(oxns:affiliation, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:affiliation"}, :terms_of_address=>{:path=>"namePart", :attributes=>{:type=>"termsOfAddress"}, :xpath_relative=>"oxns:namePart[@type=\"termsOfAddress\"]", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"termsOfAddress\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart[@type=\"termsOfAddress\"]"}, :namePart=>{:path=>"namePart", :xpath_relative=>"oxns:namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart"}, :role=>{:path=>"role", :attributes=>[{"type"=>["text", "code"]}, "authority"], :ref=>:role, :xpath_relative=>"oxns:role", :xpath_constrained=>"//oxns:name[contains(oxns:role, \\\"\#{constraint_value}\\\")]", :parents=>[:name_], :convenience_methods=>{:text=>{:path=>"roleTerm", :attributes=>{:type=>"text"}, :xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:path=>"roleTerm", :attributes=>{:type=>"code"}, :xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}, :xpath=>"//oxns:name/oxns:role"}, :displayForm=>{:path=>"displayForm", :xpath_relative=>"oxns:displayForm", :xpath_constrained=>"//oxns:name[contains(oxns:displayForm, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:displayForm"}, :description=>{:path=>"description", :xpath_relative=>"oxns:description", :xpath_constrained=>"//oxns:name[contains(oxns:description, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:description"}, :family_name=>{:path=>"namePart", :attributes=>{:type=>"family"}, :xpath_relative=>"oxns:namePart[@type=\"family\"]", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"family\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart[@type=\"family\"]"}, :date=>{:path=>"namePart", :attributes=>{:type=>"date"}, :xpath_relative=>"oxns:namePart[@type=\"date\"]", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"date\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart[@type=\"date\"]"}}}, :role=>{:path=>"role", :attributes=>[{"type"=>["text", "code"]}, "authority"], :ref=>:role, :xpath_relative=>"oxns:role", :xpath_constrained=>"//oxns:role[contains(\\\"\#{constraint_value}\\\")]", :parents=>[:name_], :xpath=>"//oxns:role", :convenience_methods=>{:text=>{:path=>"roleTerm", :attributes=>{:type=>"text"}, :xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:path=>"roleTerm", :attributes=>{:type=>"code"}, :xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}}, :title_info=>{:path=>"titleInfo", :ref=>:title_info, :xpath_relative=>"oxns:titleInfo", :xpath_constrained=>"//oxns:titleInfo[contains(\\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo", :convenience_methods=>{:main_title=>{:path=>"title", :xpath_relative=>"oxns:title", :xpath_constrained=>"//oxns:titleInfo[contains(oxns:title, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo/oxns:title"}, :language=>{:path=>"@lang", :xpath_relative=>"oxns:@lang", :xpath_constrained=>"//oxns:titleInfo[contains(oxns:@lang, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo/oxns:@lang"}}}, :unresolved=>{}}
170
+ sample_properties_hash = {:abstract=>{:xpath_relative=>"oxns:abstract", :path=>"abstract", :xpath_constrained=>"//oxns:abstract[contains(\\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:abstract", :ref=>:abstract, :convenience_methods=>{}}, :topic_tag=>{:xpath_relative=>"oxns:subject", :path=>"subject", :xpath_constrained=>"//oxns:subject[contains(oxns:topic, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:subject", :ref=>:topic_tag, :default_content_path=>"topic", :convenience_methods=>{}}, :title_info=>{:xpath_relative=>"oxns:titleInfo", :path=>"titleInfo", :xpath_constrained=>"//oxns:titleInfo[contains(\\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo", :ref=>:title_info, :convenience_methods=>{:main_title=>{:xpath_relative=>"oxns:title", :path=>"title", :xpath_constrained=>"//oxns:titleInfo[contains(oxns:title, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo/oxns:title"}, :language=>{:xpath_relative=>"@lang", :path=>{:attribute=>"lang"}, :xpath_constrained=>"//oxns:titleInfo[contains(@lang, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:titleInfo/@lang"}}}, :person=>{:xpath_relative=>"oxns:name[@type=\"personal\"]", :path=>"name", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"personal"}, :xpath=>"//oxns:name[@type=\"personal\"]", :ref=>:person, :default_content_path=>"namePart", :subelements=>["namePart", "displayForm", "affiliation", :role, "description"], :convenience_methods=>{:first_name=>{:xpath_relative=>"oxns:namePart[@type=\"given\"]", :path=>"namePart", :attributes=>{:type=>"given"}, :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"given\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"given\"]"}, :affiliation=>{:xpath_relative=>"oxns:affiliation", :path=>"affiliation", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:affiliation, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:affiliation"}, :terms_of_address=>{:xpath_relative=>"oxns:namePart[@type=\"termsOfAddress\"]", :path=>"namePart", :attributes=>{:type=>"termsOfAddress"}, :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"termsOfAddress\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"termsOfAddress\"]"}, :namePart=>{:xpath_relative=>"oxns:namePart", :path=>"namePart", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart"}, :displayForm=>{:xpath_relative=>"oxns:displayForm", :path=>"displayForm", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:displayForm, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:displayForm"}, :role=>{:xpath_relative=>"oxns:role", :path=>"role", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:role, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:role", :ref=>:role, :convenience_methods=>{:text=>{:xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :path=>"roleTerm", :attributes=>{:type=>"text"}, :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :path=>"roleTerm", :attributes=>{:type=>"code"}, :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}, :parents=>[:name_]}, :date=>{:xpath_relative=>"oxns:namePart[@type=\"date\"]", :path=>"namePart", :attributes=>{:type=>"date"}, :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"date\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"date\"]"}, :family_name=>{:xpath_relative=>"oxns:namePart[@type=\"family\"]", :path=>"namePart", :attributes=>{:type=>"family"}, :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:namePart[@type=\\\"family\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"family\"]"}, :description=>{:xpath_relative=>"oxns:description", :path=>"description", :xpath_constrained=>"//oxns:name[@type=\\\"personal\\\" and contains(oxns:description, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name[@type=\"personal\"]/oxns:description"}}, :variant_of=>:name_}, :name_=>{:xpath_relative=>"oxns:name", :path=>"name", :xpath_constrained=>"//oxns:name[contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :attributes=>[:xlink, :lang, "xml:lang", :script, :transliteration, {:type=>["personal", "enumerated", "corporate"]}], :xpath=>"//oxns:name", :ref=>:name_, :default_content_path=>"namePart", :subelements=>["namePart", "displayForm", "affiliation", :role, "description"], :convenience_methods=>{:affiliation=>{:xpath_relative=>"oxns:affiliation", :path=>"affiliation", :xpath_constrained=>"//oxns:name[contains(oxns:affiliation, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:affiliation"}, :first_name=>{:xpath_relative=>"oxns:namePart[@type=\"given\"]", :path=>"namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"given\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"given"}, :xpath=>"//oxns:name/oxns:namePart[@type=\"given\"]"}, :terms_of_address=>{:xpath_relative=>"oxns:namePart[@type=\"termsOfAddress\"]", :path=>"namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"termsOfAddress\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"termsOfAddress"}, :xpath=>"//oxns:name/oxns:namePart[@type=\"termsOfAddress\"]"}, :displayForm=>{:xpath_relative=>"oxns:displayForm", :path=>"displayForm", :xpath_constrained=>"//oxns:name[contains(oxns:displayForm, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:displayForm"}, :namePart=>{:xpath_relative=>"oxns:namePart", :path=>"namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:namePart"}, :role=>{:xpath_relative=>"oxns:role", :path=>"role", :xpath_constrained=>"//oxns:name[contains(oxns:role, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:role", :ref=>:role, :convenience_methods=>{:text=>{:xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :path=>"roleTerm", :attributes=>{:type=>"text"}, :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :path=>"roleTerm", :attributes=>{:type=>"code"}, :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}, :parents=>[:name_]}, :description=>{:xpath_relative=>"oxns:description", :path=>"description", :xpath_constrained=>"//oxns:name[contains(oxns:description, \\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:name/oxns:description"}, :family_name=>{:xpath_relative=>"oxns:namePart[@type=\"family\"]", :path=>"namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"family\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"family"}, :xpath=>"//oxns:name/oxns:namePart[@type=\"family\"]"}, :date=>{:xpath_relative=>"oxns:namePart[@type=\"date\"]", :path=>"namePart", :xpath_constrained=>"//oxns:name[contains(oxns:namePart[@type=\\\"date\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"date"}, :xpath=>"//oxns:name/oxns:namePart[@type=\"date\"]"}}}, :role=>{:xpath_relative=>"oxns:role", :path=>"role", :xpath_constrained=>"//oxns:role[contains(\\\"\#{constraint_value}\\\")]", :xpath=>"//oxns:role", :ref=>:role, :convenience_methods=>{:text=>{:xpath_relative=>"oxns:roleTerm[@type=\"text\"]", :path=>"roleTerm", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"text\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"text"}, :xpath=>"//oxns:role/oxns:roleTerm[@type=\"text\"]"}, :code=>{:xpath_relative=>"oxns:roleTerm[@type=\"code\"]", :path=>"roleTerm", :xpath_constrained=>"//oxns:role[contains(oxns:roleTerm[@type=\\\"code\\\"], \\\"\#{constraint_value}\\\")]", :attributes=>{:type=>"code"}, :xpath=>"//oxns:role/oxns:roleTerm[@type=\"code\"]"}}, :parents=>[:name_]}, :unresolved=>{}, :mods=>{:xpath_relative=>"oxns:mods", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd", :path=>"mods", :xpath_constrained=>"//oxns:mods[contains(\\\"\#{constraint_value}\\\")]", :attributes=>["id", "version"], :xpath=>"//oxns:mods", :ref=>:mods, :convenience_methods=>{}}}
171
171
  AccessorTest2.stubs(:properties).returns(sample_properties_hash)
172
-
173
172
  AccessorTest2.accessors.should be_nil
174
173
  AccessorTest2.generate_accessors_from_properties.should_not be_nil
175
174
  [:mods, :name_, :person, [:person,:first_name],[:person, :role], [:person, :role, :text] ].each do |pointer|
@@ -178,6 +177,7 @@ describe "OM::XML::Accessors" do
178
177
  ai.should_not be_nil
179
178
  ai[:relative_xpath].should_not be_nil
180
179
  end
180
+ AccessorTest2.accessor_info(*[:title_info, :language])[:relative_xpath].should == "@lang"
181
181
  end
182
182
 
183
183
  end
@@ -15,9 +15,15 @@ describe "OM::XML::Properties" do
15
15
  # root :mods_collection, :path=>"modsCollection",
16
16
  # :attributes=>[],
17
17
  # :subelements => :mods
18
-
19
- root_property :mods, "mods", "http://www.loc.gov/mods/v3", :attributes=>["id", "version"], :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"
20
18
 
19
+
20
+ root_property :mods, "mods", "http://www.loc.gov/mods/v3", :attributes=>["id", "version"], :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"
21
+
22
+ property :title_info, :path=>"titleInfo",
23
+ :convenience_methods => {
24
+ :main_title => {:path=>"title"},
25
+ :language => {:path=>{:attribute=>"lang"}},
26
+ }
21
27
 
22
28
  property :name_, :path=>"name",
23
29
  :attributes=>[:xlink, :lang, "xml:lang", :script, :transliteration, {:type=>["personal", "enumerated", "corporate"]} ],
@@ -37,7 +43,25 @@ describe "OM::XML::Properties" do
37
43
  :attributes=>[ { "type"=>["text", "code"] } , "authority"],
38
44
  :default_content_path => "roleTerm"
39
45
 
40
-
46
+ property :journal, :path=>'relatedItem', :attributes=>{:type=>"host"},
47
+ :subelements=>[:title_info, :origin_info, :issue],
48
+ :convenience_methods => {
49
+ :issn => {:path=>"identifier", :attributes=>{:type=>"issn"}},
50
+ }
51
+
52
+ property :issue, :path=>'part',
53
+ :subelements=>[:start_page, :end_page],
54
+ :convenience_methods => {
55
+ :volume => {:path=>"detail", :attributes=>{:type=>"volume"}},
56
+ :level => {:path=>"detail", :attributes=>{:type=>"level"}},
57
+ # Hack to support provisional spot for start & end page (nesting was too deep for this version of OM)
58
+ :citation_start_page => {:path=>"pages", :attributes=>{:type=>"start"}},
59
+ :citation_end_page => {:path=>"pages", :attributes=>{:type=>"end"}},
60
+ :foo => {:path=>"foo", :attributes=>{:type=>"ness"}},
61
+ :publication_date => {:path=>"date"}
62
+ }
63
+ property :start_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "start"
64
+ property :end_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "end"
41
65
  end
42
66
 
43
67
  class FakeOtherOx < Nokogiri::XML::Document
@@ -127,17 +151,30 @@ describe "OM::XML::Properties" do
127
151
  FakeOxMods.properties[:name_][:convenience_methods][:role][:xpath_constrained].should == '//oxns:name[contains(oxns:role/oxns:roleTerm, "#{constraint_value}")]'.gsub('"', '\"')
128
152
  end
129
153
 
130
- it "should create an accessor for the created property" do
131
- pending
132
- FakeOXMods.accessors.should have_key(:name_)
154
+ it "supports treating attributes as properties" do
155
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath].should == '//oxns:titleInfo/@lang'
156
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath_relative].should == '@lang'
157
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath_constrained].should == '//oxns:titleInfo[contains(@lang, "#{constraint_value}")]'.gsub('"', '\"')
133
158
  end
134
159
 
135
- it "should create accessors for subelements" do
136
- pending
137
- FakeOXMods.accessors[:name_][:children][:role][:children].should have_key(:family_name)
160
+ it "should support deep nesting of properties" do
161
+ pending "requires property method to be recursive"
162
+
163
+ FakeOxMods.properties[:journal][:convenience_methods][:issue][:convenience_methods][:volume].should == {:xpath_constrained=>"//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]", :path=>"detail", :attributes=>{:type=>"volume"}, :xpath=>"//oxns:part/oxns:detail[@type=\"volume\"]", :xpath_relative=>"oxns:detail[@type=\"volume\"]"}
164
+ prop_info = FakeOxMods.property_info_for([:journal, :issue, :volume])
165
+ prop_info[:xpath_constrained].should == "//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]"
166
+ prop_info[:xpath].should == "//oxns:part/oxns:detail[@type=\"volume\"]"
167
+ prop_info[:xpath_relative].should == "oxns:detail[@type=\"volume\"]"
138
168
  end
139
169
 
140
- it "should not overwrite default property info when adding a variant property" do
170
+ it "should support even deeper nesting of properties" do
171
+ pending "requires property method to be recursive"
172
+
173
+ FakeOxMods.properties[:journal][:convenience_methods][:issue][:convenience_methods][:start_page].should == {:xpath_constrained=>"//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]", :path=>"detail", :attributes=>{:type=>"volume"}, :xpath=>"//oxns:part/oxns:detail[@type=\"volume\"]", :xpath_relative=>"oxns:detail[@type=\"volume\"]"}
174
+ FakeOxMods.property_info_for([:journal, :issue, :end_page]).should == ""
175
+ end
176
+
177
+ it "should not overwrite default property info when adding a variant property" do
141
178
  FakeOxMods.properties[:name_].should_not equal(FakeOxMods.properties[:person])
142
179
  FakeOxMods.properties[:name_][:convenience_methods].should_not equal(FakeOxMods.properties[:person][:convenience_methods])
143
180
 
@@ -249,6 +286,13 @@ describe "OM::XML::Properties" do
249
286
  FakeOxMods.builder_template([:person,:role], {:attributes=>{"type"=>"code", "authority"=>"marcrelator"}} ).should == marcrelator_role_builder_template
250
287
  end
251
288
 
289
+ it "should work with deeply nested properties" do
290
+ pending "requires property method to be recursive"
291
+
292
+ FakeOxMods.builder_template([:journal, :issue, :volume]).should == "fixme"
293
+ FakeOxMods.builder_template([:journal, :issue, :start_page]).should == "fixme"
294
+ end
295
+
252
296
  end
253
297
 
254
298
  describe "#applicable_attributes" do
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
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-06-30 00:00:00 -05:00
18
+ date: 2010-07-02 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency