Class: ImgFetcher::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/img_fetcher/main.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Main

Returns a new instance of Main.



3
4
5
6
7
8
# File 'lib/img_fetcher/main.rb', line 3

def initialize(arguments)
  @arguments = arguments
  @stats = Stats.new
  @terminal = Helpers::Terminal
  @threads = [] if @arguments[:threaded]
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/img_fetcher/main.rb', line 10

def run
  start_stats
  File.open(@arguments[:file_path], 'r').each_with_index do |line, index|
    if @arguments[:threaded]
      @threads << Thread.new { manage_line(line, index + 1) }
    else
      manage_line(line, index + 1)
    end
  end
  @threads.each(&:join) if @arguments[:threaded]
  end_stats
end