Class: Locator::Result
- Inherits:
-
Array
- Object
- Array
- Locator::Result
- Defined in:
- lib/locator/result.rb
Constant Summary collapse
- MATCH_TYPES =
{ :alt => :contains, :title => :contains, :content => :contains }
Class Method Summary collapse
- .contains?(value, selector) ⇒ Boolean
- .equals?(value, selector) ⇒ Boolean
- .matches?(name, value, selector) ⇒ Boolean
- .normalize_whitespace(value) ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #filter(selector, locatables) ⇒ Object
- #filter!(selector, locatables) ⇒ Object
- #sort! ⇒ Object
Class Method Details
.contains?(value, selector) ⇒ Boolean
25 26 27 |
# File 'lib/locator/result.rb', line 25 def contains?(value, selector) value.include?(selector) end |
.equals?(value, selector) ⇒ Boolean
21 22 23 |
# File 'lib/locator/result.rb', line 21 def equals?(value, selector) value == selector end |
.matches?(name, value, selector) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/locator/result.rb', line 10 def matches?(name, value, selector) value = normalize_whitespace(value) case selector when Regexp value =~ selector else type = MATCH_TYPES[name] || :equals send("#{type}?", value, selector) end end |
.normalize_whitespace(value) ⇒ Object
29 30 31 |
# File 'lib/locator/result.rb', line 29 def normalize_whitespace(value) value.gsub(/\s+/, ' ').strip end |
Instance Method Details
#+(other) ⇒ Object
47 48 49 |
# File 'lib/locator/result.rb', line 47 def +(other) replace(super) end |
#filter(selector, locatables) ⇒ Object
38 39 40 |
# File 'lib/locator/result.rb', line 38 def filter(selector, locatables) selector ? filter_by(selector, locatables) : self end |
#filter!(selector, locatables) ⇒ Object
34 35 36 |
# File 'lib/locator/result.rb', line 34 def filter!(selector, locatables) selector ? replace(filter(selector, locatables)) : self end |
#sort! ⇒ Object
42 43 44 45 |
# File 'lib/locator/result.rb', line 42 def sort! each { |element| element.matches.sort! } super { |lft, rgt| lft.matches.first.length <=> rgt.matches.first.length } end |