Class: Xapian::Indexer::Controller
- Inherits:
-
Object
- Object
- Xapian::Indexer::Controller
- Defined in:
- lib/xapian/indexer/resource.rb
Instance Attribute Summary collapse
-
#extractors ⇒ Object
readonly
Returns the value of attribute extractors.
-
#loaders ⇒ Object
readonly
Returns the value of attribute loaders.
Instance Method Summary collapse
- #create(name) ⇒ Object
-
#initialize(options = {}) ⇒ Controller
constructor
A new instance of Controller.
- #load(resource, &block) ⇒ Object
- #recreate(data) ⇒ Object
- #save(resource) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Controller
Returns a new instance of Controller.
28 29 30 31 32 33 |
# File 'lib/xapian/indexer/resource.rb', line 28 def initialize( = {}) @extractors = {} @loaders = [] @logger = [:logger] || Logger.new($stderr) end |
Instance Attribute Details
#extractors ⇒ Object (readonly)
Returns the value of attribute extractors.
36 37 38 |
# File 'lib/xapian/indexer/resource.rb', line 36 def extractors @extractors end |
#loaders ⇒ Object (readonly)
Returns the value of attribute loaders.
35 36 37 |
# File 'lib/xapian/indexer/resource.rb', line 35 def loaders @loaders end |
Instance Method Details
#create(name) ⇒ Object
38 39 40 |
# File 'lib/xapian/indexer/resource.rb', line 38 def create(name) Resource.new(name, self) end |
#load(resource, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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 = extractor.call(resource, status, header, body) # Load the data into the resource yield status, header, body, 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'] = { :links => [location.to_s] } # This resource is not indexable, using nil for body yield status, header, nil, end end end return false end |
#recreate(data) ⇒ Object
83 84 85 86 87 |
# File 'lib/xapian/indexer/resource.rb', line 83 def recreate(data) values = YAML::load(data) Resource.new(values[:name], self, values) end |
#save(resource) ⇒ Object
79 80 81 |
# File 'lib/xapian/indexer/resource.rb', line 79 def save(resource) YAML::dump(resource.to_hash) end |