Class: Downlow::Extractor
- Inherits:
-
Object
- Object
- Downlow::Extractor
- Defined in:
- lib/downlow/extractor.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#final_path ⇒ Object
readonly
Returns the value of attribute final_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
Class Method Summary collapse
- .extract(url, options = {}) ⇒ Object
- .extractor_for(path) ⇒ Object
- .handles(which, options = {}) ⇒ Object
Instance Method Summary collapse
- #extract ⇒ Object
- #extracted? ⇒ Boolean
-
#initialize(path, options = {}) ⇒ Extractor
constructor
A new instance of Extractor.
Constructor Details
#initialize(path, options = {}) ⇒ Extractor
Returns a new instance of Extractor.
29 30 31 32 33 34 35 |
# File 'lib/downlow/extractor.rb', line 29 def initialize(path, = {}) @path = Pathname.new(path) @options = @tmp_dir = Pathname.new([:tmp_dir] || 'tmp'). + 'extract' @tmp_dir.mkpath @destination = Pathname.new([:destination] || tmp_dir + self.path.stem). end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
27 28 29 |
# File 'lib/downlow/extractor.rb', line 27 def destination @destination end |
#final_path ⇒ Object (readonly)
Returns the value of attribute final_path.
26 27 28 |
# File 'lib/downlow/extractor.rb', line 26 def final_path @final_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/downlow/extractor.rb', line 26 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/downlow/extractor.rb', line 26 def path @path end |
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
27 28 29 |
# File 'lib/downlow/extractor.rb', line 27 def tmp_dir @tmp_dir end |
Class Method Details
.extract(url, options = {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/downlow/extractor.rb', line 19 def self.extract(url, = {}) klass = extractor_for(url) extractor = klass.new(url, ) extractor.extract extractor.final_path end |
.extractor_for(path) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/downlow/extractor.rb', line 9 def self.extractor_for(path) @@handlers.each do |matcher, , klass| if [:file_only] && !File.file?(path) next else return klass if matcher.match(path) end end end |
.handles(which, options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/downlow/extractor.rb', line 4 def self.handles(which, = {}) @@handlers ||= [] @@handlers << [which, , self] end |
Instance Method Details
#extract ⇒ Object
37 38 39 |
# File 'lib/downlow/extractor.rb', line 37 def extract raise "Should be overridden by subclass" end |
#extracted? ⇒ Boolean
41 42 43 |
# File 'lib/downlow/extractor.rb', line 41 def extracted? !!@final_path end |