Class: Pincers::Support::Query
- Inherits:
-
Object
- Object
- Pincers::Support::Query
- Defined in:
- lib/pincers/support/query.rb
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #execute(_elements, _force_limit = nil) ⇒ Object
- #explode_elements(_elements, _fun, _limit) ⇒ Object
-
#initialize(_backend, _lang, _query, _limit) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(_backend, _lang, _query, _limit) ⇒ Query
Returns a new instance of Query.
6 7 8 9 10 11 |
# File 'lib/pincers/support/query.rb', line 6 def initialize(_backend, _lang, _query, _limit) @backend = _backend @lang = _lang @query = _query @limit = _limit end |
Instance Attribute Details
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
4 5 6 |
# File 'lib/pincers/support/query.rb', line 4 def lang @lang end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/pincers/support/query.rb', line 4 def limit @limit end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
4 5 6 |
# File 'lib/pincers/support/query.rb', line 4 def query @query end |
Instance Method Details
#execute(_elements, _force_limit = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pincers/support/query.rb', line 13 def execute(_elements, _force_limit=nil) fun = case @lang when :xpath then :search_by_xpath else :search_by_css end explode_elements _elements, fun, _force_limit || @limit end |
#explode_elements(_elements, _fun, _limit) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/pincers/support/query.rb', line 21 def explode_elements(_elements, _fun, _limit) _elements.inject([]) do |r, element| limit = _limit.nil? ? nil : _limit - r.count r = r + @backend.send(_fun, element, @query, limit) break r if !_limit.nil? && r.length >= _limit next r end end |