nom-xml 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,8 @@ module Nom::XML::Decorators::Terminology
15
15
 
16
16
  xpath = t.local_xpath
17
17
 
18
- xpath += "[#{t.options[:if]}]" if t.options[:if]
19
- xpath += "[not(#{t.options[:unless]})]" if t.options[:unless]
18
+ xpath += "[#{t.options[:if]}]" if t.options[:if] and t.options[:if].is_a? String
19
+ xpath += "[not(#{t.options[:unless]})]" if t.options[:unless] and t.options[:unless].is_a? String
20
20
 
21
21
  xpath += "[#{args.join('][')}]" unless args.empty?
22
22
 
@@ -27,6 +27,8 @@ module Nom::XML::Decorators::Terminology
27
27
  self.xpath(xpath, self.document.terminology_namespaces)
28
28
  end
29
29
 
30
+ result = result.select &t.options[:if] if t.options[:if].is_a? Proc
31
+ result = result.reject &t.options[:unless] if t.options[:unless].is_a? Proc
30
32
 
31
33
  m = t.options[:accessor]
32
34
  return_value = case
@@ -1,5 +1,5 @@
1
1
  module Nom
2
2
  module XML
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -12,6 +12,8 @@ describe "Nutrition" do
12
12
  dv.total_fat :path => 'total-fat' do |tf|
13
13
  tf.value :path => '.', :accessor => lambda { |node| node.text.to_i }
14
14
  tf.units :path => '@units'
15
+ tf.units_if :path => '@units', :if => lambda { |node| true }
16
+ tf.units_if_false :path => '@units', :if => lambda { |node| false }
15
17
  end
16
18
  end
17
19
 
@@ -55,4 +57,9 @@ describe "Nutrition" do
55
57
  subject.daily_values.total_fat.unit_value.should include('65g')
56
58
  subject.foods.first.at('serving').unit_value.should include('29g')
57
59
  end
60
+
61
+ it "should accept if in proc-form" do
62
+ subject.daily_values.total_fat.units_if == subject.daily_values.total_fat.units
63
+ subject.daily_values.total_fat.units_if_false.should be_empty
64
+ end
58
65
  end
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.1.1
4
+ version: 0.1.2
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: -2240857808020887200
177
+ hash: -3641921164440724288
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: -2240857808020887200
186
+ hash: -3641921164440724288
187
187
  requirements: []
188
188
  rubyforge_project:
189
189
  rubygems_version: 1.8.23