Class: Sc::UriPatternSelector

Inherits:
Selector
  • Object
show all
Defined in:
lib/scrappy/extractor/selectors/uri_pattern.rb

Instance Method Summary collapse

Methods inherited from Selector

#select

Methods included from Scrappy::Formats

#format

Instance Method Details

#filter(doc) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/scrappy/extractor/selectors/uri_pattern.rb', line 3

def filter doc
  # Check if the uri fits the pattern
  if rdf::value.any? { |v| doc[:uri] =~ /\A#{v.gsub('.','\.').gsub('*', '.+').gsub('?', '\?')}\Z/ }
    [ { :uri=>doc[:uri], :content=>doc[:content], :value=>format(doc[:value], sc::format, doc[:uri]) } ]
  else
    []
  end
end