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



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

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



51
52
53
# File 'lib/right_scraper/scanners/union.rb', line 51

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



59
60
61
# File 'lib/right_scraper/scanners/union.rb', line 59

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

#finishObject

Notify subscanners that all scans have completed.



43
44
45
# File 'lib/right_scraper/scanners/union.rb', line 43

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



71
72
73
74
75
76
77
78
# File 'lib/right_scraper/scanners/union.rb', line 71

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



88
89
90
# File 'lib/right_scraper/scanners/union.rb', line 88

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