Class: Picdown::Download
- Inherits:
-
Object
- Object
- Picdown::Download
- Defined in:
- lib/picdown/download.rb
Instance Attribute Summary collapse
-
#bars ⇒ Object
readonly
Returns the value of attribute bars.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(file, **opts) ⇒ Download
constructor
A new instance of Download.
- #perform_parallel ⇒ Object
- #perform_sequential ⇒ Object
Constructor Details
#initialize(file, **opts) ⇒ Download
Returns a new instance of Download.
12 13 14 15 16 |
# File 'lib/picdown/download.rb', line 12 def initialize(file, **opts) @source = SourceFile.load(file) @config = Config.new(opts) @bars = TTY::ProgressBar::Multi.new end |
Instance Attribute Details
#bars ⇒ Object (readonly)
Returns the value of attribute bars.
10 11 12 |
# File 'lib/picdown/download.rb', line 10 def @bars end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/picdown/download.rb', line 10 def config @config end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/picdown/download.rb', line 10 def source @source end |
Class Method Details
.from_file(file, **opts) ⇒ Object
33 34 35 |
# File 'lib/picdown/download.rb', line 33 def from_file(file, **opts) new(file, **opts).call end |
Instance Method Details
#call ⇒ Object
18 19 20 |
# File 'lib/picdown/download.rb', line 18 def call config.parallel <= 1 ? perform_sequential : perform_parallel end |
#perform_parallel ⇒ Object
26 27 28 29 30 |
# File 'lib/picdown/download.rb', line 26 def perform_parallel threads = MultiThread.new(config.parallel) source.downloadable.each { |src| threads.add { download(src) } } threads.invoke end |
#perform_sequential ⇒ Object
22 23 24 |
# File 'lib/picdown/download.rb', line 22 def perform_sequential source.downloadable.each { |src| download(src) } end |