Class: ImgFetcher::Stats

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



5
6
7
8
9
10
11
# File 'lib/img_fetcher/stats.rb', line 5

def initialize
  @total_lines      = 0
  @retrieved_images = 0
  @semaphore        = Mutex.new
  @start_time       = nil
  @end_time         = nil
end

Instance Attribute Details

#retrieved_imagesObject (readonly)

Returns the value of attribute retrieved_images.



3
4
5
# File 'lib/img_fetcher/stats.rb', line 3

def retrieved_images
  @retrieved_images
end

#total_linesObject (readonly)

Returns the value of attribute total_lines.



3
4
5
# File 'lib/img_fetcher/stats.rb', line 3

def total_lines
  @total_lines
end

Instance Method Details

#add_lineObject



13
14
15
16
17
# File 'lib/img_fetcher/stats.rb', line 13

def add_line
  @semaphore.synchronize do
    @total_lines += 1
  end
end

#add_retrieved_imageObject



19
20
21
22
23
# File 'lib/img_fetcher/stats.rb', line 19

def add_retrieved_image
  @semaphore.synchronize do
    @retrieved_images += 1
  end
end

#endObject



29
30
31
# File 'lib/img_fetcher/stats.rb', line 29

def end
  @end_time = now
end

#startObject



25
26
27
# File 'lib/img_fetcher/stats.rb', line 25

def start
  @start_time = now
end

#total_timeObject



33
34
35
# File 'lib/img_fetcher/stats.rb', line 33

def total_time
  @end_time - @start_time
end