Class: Forklift::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/forklift/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, number) ⇒ Worker

Returns a new instance of Worker.



6
7
8
9
10
11
12
# File 'lib/forklift/worker.rb', line 6

def initialize(logger, number)
  @i = 0
  @number = number
  @tick = Time.now.to_i
  @logger = logger
  logger.debug "Worker #{number} spawned"
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/forklift/worker.rb', line 4

def logger
  @logger
end

#numberObject (readonly)

Returns the value of attribute number.



4
5
6
# File 'lib/forklift/worker.rb', line 4

def number
  @number
end

Instance Method Details

#==(other_nr) ⇒ Object

worker objects may be compared to just plain Integers



15
16
17
# File 'lib/forklift/worker.rb', line 15

def ==(other_nr) # :nodoc:
  @number == other_nr
end

#closeObject

:nodoc:



31
32
33
# File 'lib/forklift/worker.rb', line 31

def close # :nodoc:
  @tmp.close if @tmp
end

#nrObject



27
28
29
# File 'lib/forklift/worker.rb', line 27

def nr
  @number
end

#performObject



35
36
37
38
39
# File 'lib/forklift/worker.rb', line 35

def perform
  @i += 1
  logger.info "Working #{@i}"
  sleep 5
end

#tickObject



23
24
25
# File 'lib/forklift/worker.rb', line 23

def tick
  @tick
end

#tick=(int) ⇒ Object



19
20
21
# File 'lib/forklift/worker.rb', line 19

def tick=(int)
  @tick = int
end