Class: Locator::Result
- Inherits:
-
Array
- Object
- Array
- Locator::Result
- Defined in:
- lib/locator/result.rb
Class Method Summary collapse
- .equals?(value, selector) ⇒ Boolean
- .matches?(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
.equals?(value, selector) ⇒ Boolean
4 5 6 |
# File 'lib/locator/result.rb', line 4 def equals?(value, selector) value == selector end |
.matches?(value, selector) ⇒ Boolean
8 9 10 11 |
# File 'lib/locator/result.rb', line 8 def matches?(value, selector) value = normalize_whitespace(value) Regexp === selector ? value =~ selector : value.include?(selector) end |
.normalize_whitespace(value) ⇒ Object
13 14 15 |
# File 'lib/locator/result.rb', line 13 def normalize_whitespace(value) value.gsub(/\s+/, ' ').strip end |
Instance Method Details
#+(other) ⇒ Object
31 32 33 |
# File 'lib/locator/result.rb', line 31 def +(other) replace(super) end |
#filter(selector, locatables) ⇒ Object
22 23 24 |
# File 'lib/locator/result.rb', line 22 def filter(selector, locatables) selector ? locatables.map { |(type, attrs)| filter_by(type, selector, attrs) }.flatten : self end |
#filter!(selector, locatables) ⇒ Object
18 19 20 |
# File 'lib/locator/result.rb', line 18 def filter!(selector, locatables) selector ? replace(filter(selector, locatables)) : self end |
#sort! ⇒ Object
26 27 28 29 |
# File 'lib/locator/result.rb', line 26 def sort! each { |element| element.matches.sort! } super { |lft, rgt| lft.matches.first.length <=> rgt.matches.first.length } end |