class Apist::Filter
Attributes
method[R]
node[R]
resource[R]
Public Class Methods
new(node, method)
click to toggle source
# File lib/apist/filter.rb, line 8 def initialize(node, method) @node = node @method = method @resource = method.resource end
Public Instance Methods
attr(attribute)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 89 def attr(attribute) guard_crawler @node.attr(attribute).to_s end
call(block)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 124 def call(block) block.call @node end
check(block)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 170 def check(block) call block end
children()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 45 def children guard_crawler @node.children end
closest(selector)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 82 def closest(selector) guard_crawler node = get_node node.ancestors(selector).last end
each(blueprint = nil)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 187 def each(blueprint = nil) callback = blueprint if callback.nil? callback = lambda { |node, i| node } end unless callback.is_a? Proc callback = lambda { |node, i| @method.parse_blueprint blueprint.clone, node } end result = [] @node.each do |node| result << callback.call(node, result.length) end result end
element()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 119 def element @node end
else(blueprint)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 181 def else(blueprint) return @node unless @node === false return @method.parse_blueprint blueprint end
eq(position)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 101 def eq(position) guard_crawler @node.at position end
exists()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 165 def exists !@node.empty? end
filter(selector)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 27 def filter(selector) guard_crawler @node.css selector end
filter_nodes(selector)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 33 def filter_nodes(selector) guard_crawler @node.filter selector end
find(selector)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 39 def find(selector) guard_crawler @node.css selector end
first()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 107 def first guard_crawler @node.first end
gsub(*several_variants)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 147 def gsub(*several_variants) guard_text @node.send :gsub, *several_variants end
hasAttr(attribute)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 95 def hasAttr(attribute) guard_crawler @node.attr(attribute) != nil end
html()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 21 def html guard_crawler @node.inner_html end
is(selector)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 75 def is(selector) guard_crawler node = get_node node.matches? selector end
last()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 113 def last guard_crawler @node.last end
lstrip()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 135 def lstrip guard_text @node.lstrip end
next()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 63 def next guard_crawler next_all[0] end
next_all()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 69 def next_all guard_crawler sibling 'next' end
prev()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 51 def prev guard_crawler prev_all[0] end
prev_all()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 57 def prev_all guard_crawler sibling 'previous' end
rstrip()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 141 def rstrip guard_text @node.rstrip end
strip()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 129 def strip guard_text @node.strip end
text()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 15 def text guard_crawler @node.text end
then(blueprint)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 175 def then(blueprint) return @node unless @node === true return @method.parse_blueprint blueprint end
to_f()
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 159 def to_f guard_text @node.to_f end
to_i(base = 10)
click to toggle source
@return [Apist::Filter]
# File lib/apist/filter.rb, line 153 def to_i(base = 10) guard_text @node.to_i base end
Private Instance Methods
get_node()
click to toggle source
# File lib/apist/filter.rb, line 212 def get_node return @node[0] if @node.is_a? Nokogiri::XML::NodeSet @node end
guard_crawler()
click to toggle source
# File lib/apist/filter.rb, line 230 def guard_crawler unless is_node raise Apist::MethodError, 'Current node isnt instance of Nokogiri Node or NodeSet.' end end
guard_text()
click to toggle source
# File lib/apist/filter.rb, line 226 def guard_text @node = @node.text if is_node end
is_node()
click to toggle source
# File lib/apist/filter.rb, line 208 def is_node @node.is_a? Nokogiri::XML::NodeSet or @node.is_a? Nokogiri::XML::Node end
sibling(direction)
click to toggle source
# File lib/apist/filter.rb, line 217 def sibling(direction) nodes = [] node = get_node while (node = node.send(direction)) != nil nodes << node if node.node_type === 1 end nodes end