Class: RightScraper::Scanners::Union

Inherits:
Object
  • Object
show all
Defined in:
lib/right_scraper/scanners/union.rb

Overview

Union scanner, to permit running multiple scanners while only walking the fs once.

Instance Method Summary collapse

Constructor Details

#initialize(classes, options = {}) ⇒ Union

Create a new union scanner. Recognizes no new options.

Parameters

classes(List)

List of Scanner classes to run

options(Hash)

scanner options



34
35
36
# File 'lib/right_scraper/scanners/union.rb', line 34

def initialize(classes, options={})
  @subscanners = classes.map {|klass| klass.new(options)}
end

Instance Method Details

#begin(resource) ⇒ Object

Begin a scan for the given resource.

Parameters

resource(RightScraper::Resource::Base)

resource to scan



47
48
49
# File 'lib/right_scraper/scanners/union.rb', line 47

def begin(resource)
  @subscanners.each {|scanner| scanner.begin(resource)}
end

#end(resource) ⇒ Object

Finish a scan for the given resource.

Parameters

resource(RightScraper::Resource::Base)

resource that just finished scanning



55
56
57
# File 'lib/right_scraper/scanners/union.rb', line 55

def end(resource)
  @subscanners.each {|scanner| scanner.end(resource)}
end

#finishObject

Notify subscanners that all scans have completed.



39
40
41
# File 'lib/right_scraper/scanners/union.rb', line 39

def finish
  @subscanners.each {|scanner| scanner.finish}
end

#notice(relative_position) ⇒ Object

Notice a file during scanning.

Block

Return the data for this file. We use a block because it may not always be necessary to read the data.

Parameters

relative_position(String)

relative pathname for the file from the root of resource



67
68
69
70
71
72
73
74
# File 'lib/right_scraper/scanners/union.rb', line 67

def notice(relative_position)
  data = nil
  @subscanners.each {|scanner| scanner.notice(relative_position) {
      data = yield if data.nil?
      data
    }
  }
end

#notice_dir(relative_position) ⇒ Object

Notice a directory during scanning. Returns true if any of the subscanners report that they should recurse into the directory.

Parameters

relative_position(String)

relative pathname for directory from root of resource

Returns

Boolean

should the scanning recurse into the directory



84
85
86
# File 'lib/right_scraper/scanners/union.rb', line 84

def notice_dir(relative_position)
  @subscanners.any? {|scanner| scanner.notice_dir(relative_position)}
end