Module: Mechanize::ElementMatcher

Included in:
Form, Form::MultiSelectList, Page
Defined in:
lib/mechanize/element_matcher.rb

Instance Method Summary collapse

Instance Method Details

#elements_with(singular, plural = "#{singular}s") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mechanize/element_matcher.rb', line 3

def elements_with singular, plural = "#{singular}s"
  class_eval "    def \#{plural}_with criteria = {}\n      criteria = if String === criteria then\n                   {:name => criteria}\n                 else\n                   criteria.map do |k, v|\n                     k = :dom_id if k.to_sym == :id\n                     k = :dom_class if k.to_sym == :class\n                     [k, v]\n                   end\n                 end\n\n      f = \#{plural}.find_all do |thing|\n        criteria.all? do |k,v|\n          v === thing.send(k)\n        end\n      end\n      yield f if block_given?\n      f\n    end\n\n    def \#{singular}_with criteria = {}\n      f = \#{plural}_with(criteria).first\n      yield f if block_given?\n      f\n    end\n\n    alias :\#{singular} :\#{singular}_with\n  CODE\nend\n"