Class: Picdown::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/picdown/download.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#barsObject (readonly)

Returns the value of attribute bars.



10
11
12
# File 'lib/picdown/download.rb', line 10

def bars
  @bars
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/picdown/download.rb', line 10

def config
  @config
end

#sourceObject (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

#callObject



18
19
20
# File 'lib/picdown/download.rb', line 18

def call
  config.parallel <= 1 ? perform_sequential : perform_parallel
end

#perform_parallelObject



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_sequentialObject



22
23
24
# File 'lib/picdown/download.rb', line 22

def perform_sequential
  source.downloadable.each { |src| download(src) }
end