module Apify::Core::Filter
Public Class Methods
apply(node_or_str, filters=[])
click to toggle source
# File lib/apify_core/filter.rb, line 6 def apply(node_or_str, filters=[]) return node_or_str if filters.empty? or node_or_str.nil? method = filters.shift filtered_value = send(method, node_or_str) apply(filtered_value, filters) end
Private Class Methods
first(node)
click to toggle source
# File lib/apify_core/filter.rb, line 15 def first(node) node.first end
html(node)
click to toggle source
# File lib/apify_core/filter.rb, line 31 def html(node) node.to_s end
inner_html(node)
click to toggle source
# File lib/apify_core/filter.rb, line 35 def inner_html(node) node.inner_html.to_s end
list(node)
click to toggle source
# File lib/apify_core/filter.rb, line 27 def list(node) node end
map_html(node)
click to toggle source
# File lib/apify_core/filter.rb, line 43 def map_html(node) node.map(&:to_s) end
map_inner_html(node)
click to toggle source
# File lib/apify_core/filter.rb, line 47 def map_inner_html(node) node.map(&:inner_html).map(&:to_s) end
map_text(node)
click to toggle source
# File lib/apify_core/filter.rb, line 39 def map_text(node) node.map(&:text).map(&:strip) end
map_urlencode(node)
click to toggle source
# File lib/apify_core/filter.rb, line 52 def map_urlencode(node) node.map do |url| urlencode(url) end end
method_missing(method_sym, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/apify_core/filter.rb, line 67 def method_missing(method_sym, *arguments, &block) if method_sym =~ /\Amapattr_/ attribute = method_sym.to_s.gsub('mapattr_', '') arguments.first.map{ |n| n[attribute] } elsif method_sym =~ /\Aattr_/ attribute = method_sym.to_s.gsub('attr_', '') arguments.first[attribute] else super end end
strip(str)
click to toggle source
# File lib/apify_core/filter.rb, line 23 def strip(str) str.strip if str end
text(node)
click to toggle source
# File lib/apify_core/filter.rb, line 19 def text(node) node.text end
urlencode(url)
click to toggle source
# File lib/apify_core/filter.rb, line 58 def urlencode(url) url = begin url = URI(url) url rescue URI::InvalidURIError URI.encode(url) end end