Skip to content

Commit

Permalink
add #value?, plus test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatzFan committed Dec 14, 2018
1 parent dfb25f3 commit a15e122
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/nokogiri/xml/node.rb
Expand Up @@ -348,6 +348,12 @@ def values
attribute_nodes.map(&:value)
end

###
# Does this Node's attributes include <value>
def value?(value)
values.include? value
end

###
# Get the attribute names for this Node.
def keys
Expand Down
5 changes: 5 additions & 0 deletions test/xml/test_node.rb
Expand Up @@ -644,6 +644,11 @@ def test_values
assert_equal %w{ Yes Yes }, @xml.xpath('//address')[1].values
end

def test_value?
refute @xml.xpath('//address')[1].value?('no_such_value')
assert @xml.xpath('//address')[1].value?('Yes')
end

def test_keys
assert_equal %w{ domestic street }, @xml.xpath('//address')[1].keys
end
Expand Down

0 comments on commit a15e122

Please sign in to comment.