Class: Locator::Result

Inherits:
Array
  • Object
show all
Defined in:
lib/locator/result.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.equals?(value, selector) ⇒ Boolean

Returns:



4
5
6
# File 'lib/locator/result.rb', line 4

def equals?(value, selector)
  value == selector
end

.matches?(value, selector) ⇒ Boolean

Returns:



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