forked from sparklemotion/mechanize
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor common code out of Page and Form and simplify it
- Loading branch information
Showing
4 changed files
with
66 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Mechanize::ElementMatcher | ||
|
||
def elements_with singular, plural = "#{singular}s" | ||
class_eval <<-CODE | ||
def #{plural}_with criteria = {} | ||
criteria = if String === criteria then | ||
{:name => criteria} | ||
else | ||
criteria.map do |k, v| | ||
k = :dom_id if k.to_sym == :id | ||
[k, v] | ||
end | ||
end | ||
f = #{plural}.find_all do |thing| | ||
criteria.all? do |k,v| | ||
v === thing.send(k) | ||
end | ||
end | ||
yield f if block_given? | ||
f | ||
end | ||
def #{singular}_with criteria = {} | ||
f = #{plural}_with(criteria).first | ||
yield f if block_given? | ||
f | ||
end | ||
alias :#{singular} :#{singular}_with | ||
CODE | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters