Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #value?, plus test #1840

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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