nom-xml 0.0.7 → 0.0.8

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.
@@ -52,11 +52,19 @@ module Nom::XML::Decorators::Terminology
52
52
  ##
53
53
  # Get the terminology terms associated with this node
54
54
  def terms
55
- return {} unless self.respond_to? :parent and not self.parent.term_accessors.empty?
55
+ return @terms if @terms
56
+ p = self.parent
56
57
 
57
- self.parent.term_accessors.select do |k,term|
58
- self.parent.xpath(term.local_xpath, self.document.terminology_namespaces).include? self
59
- end.map { |k, term| term }
58
+ t = []
59
+
60
+ until p.is_a? Nokogiri::XML::Document
61
+ p.term_accessors.each do |k,term|
62
+ t << term if term.nodes.include? self
63
+ end
64
+ p = p.parent
65
+ end
66
+
67
+ @terms ||= t
60
68
  end
61
69
 
62
70
  protected
@@ -87,6 +87,10 @@ module Nom::XML
87
87
  end
88
88
  end
89
89
 
90
+ def to_s
91
+ "#<Nom::XML::Term name=#{name}>"
92
+ end
93
+
90
94
  protected
91
95
  def in_edit_context &block
92
96
  @edit_context = true
@@ -1,5 +1,5 @@
1
1
  module Nom
2
2
  module XML
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
  end
5
5
  end
@@ -16,7 +16,9 @@ describe "Namespaces example" do
16
16
 
17
17
  t.corporate_authors :path => '//mods:name[@type="corporate"]'
18
18
  t.personal_authors :path => 'mods:name[@type="personal"]' do |n|
19
- n.roleTerm :path => 'mods:role/mods:roleTerm', :index_as => [:type_1]
19
+ n.roleTerm :path => 'mods:role/mods:roleTerm', :index_as => [:type_1] do |r|
20
+ r.type :path => '@type'
21
+ end
20
22
 
21
23
  n.name_role_pair :path => '.', :accessor => lambda { |node| node.roleTerm.text + ": " + node.namePart.text }
22
24
 
@@ -64,6 +66,8 @@ describe "Namespaces example" do
64
66
 
65
67
  eric.namePart.text.should == "Alterman, Eric"
66
68
  eric.roleTerm.text.should == "creator"
69
+
70
+ eric.roleTerm.type.text.should == "text"
67
71
  end
68
72
 
69
73
  it "should let you mix and match xpaths and nom accessors" do
@@ -81,7 +85,7 @@ describe "Namespaces example" do
81
85
  end
82
86
 
83
87
  it "should let you go from a terminology to nodes" do
84
- subject.terminology.flatten.length.should == 10
88
+ subject.terminology.flatten.length.should == 11
85
89
 
86
90
  subject.terminology.flatten.select { |x| x.options[:index_as] }.should have(2).terms
87
91
  subject.terminology.flatten.select { |x| x.options[:index_as] }.map { |x| x.nodes }.flatten.should have(2).nodes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nom-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  segments:
176
176
  - 0
177
- hash: 2351930484694908071
177
+ hash: 4560285643406046416
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  none: false
180
180
  requirements:
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  segments:
185
185
  - 0
186
- hash: 2351930484694908071
186
+ hash: 4560285643406046416
187
187
  requirements: []
188
188
  rubyforge_project:
189
189
  rubygems_version: 1.8.23