-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable the chaining of selector aliases
- Loading branch information
Showing
3 changed files
with
93 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
module Elementor | ||
class ElementSet < Array | ||
attr_accessor :result, :selector | ||
|
||
def with_text(str) | ||
ElementSet.new(select { |item| item.text.include?(str) }) | ||
replace(select { |item| | ||
item.text.include?(str) | ||
}) ; self | ||
end | ||
|
||
def with_attrs(options={}) | ||
ElementSet.new(select { |item| | ||
replace(select { |item| | ||
options.all? { |key, value| item[key.to_s] == value } | ||
}) | ||
}) ; self | ||
end | ||
|
||
def inspect | ||
map(&:text).inspect | ||
end | ||
|
||
def method_missing(sym, *args, &block) | ||
result.try(sym, doc, *args) || super | ||
end | ||
|
||
def respond_to?(sym) | ||
result.respond_to?(sym) || super | ||
end | ||
|
||
def doc | ||
result.doc.search(selector) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters