class Xapian::Indexer::Controller
Attributes
extractors[R]
loaders[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/xapian/indexer/resource.rb, line 28 def initialize(options = {}) @extractors = {} @loaders = [] @logger = options[:logger] || Logger.new($stderr) end
Public Instance Methods
create(name)
click to toggle source
# File lib/xapian/indexer/resource.rb, line 38 def create(name) Resource.new(name, self) end
load(resource) { |status, header, body, metadata| ... }
click to toggle source
# File lib/xapian/indexer/resource.rb, line 42 def load(resource, &block) @loaders.each do |loader| loader.call(resource.name) do |status, header, load_body| if status >= 200 && status < 300 # Process the page content mime_type = header['content-type'].split(";").first extractor = @extractors[mime_type] if extractor body = load_body.call metadata = extractor.call(resource, status, header, body) # Load the data into the resource yield status, header, body, metadata return true else @logger.warn "Ignoring resource #{resource.name} because content-type #{mime_type} is not supported." return false end elsif status >= 300 && status < 400 # Process the redirect location = URI.parse(resource.name) + header['location'] metadata = { :links => [location.to_s] } # This resource is not indexable, using nil for body yield status, header, nil, metadata end end end return false end
recreate(data)
click to toggle source
# File lib/xapian/indexer/resource.rb, line 83 def recreate(data) values = YAML::load(data) Resource.new(values[:name], self, values) end
save(resource)
click to toggle source
# File lib/xapian/indexer/resource.rb, line 79 def save(resource) YAML::dump(resource.to_hash) end