Skip to content

Commit

Permalink
Merge pull request #1840 from MatzFan/add_value_predicate_to_node
Browse files Browse the repository at this point in the history
add #value?, plus test
  • Loading branch information
flavorjones committed Jan 27, 2020
2 parents d32e332 + 4909ff3 commit 6877a1a
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 @@ -349,6 +349,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 6877a1a

Please sign in to comment.