Class: Shifty::Roster

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shifty/roster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workers = []) ⇒ Roster

Returns a new instance of Roster.



9
10
11
12
13
14
# File 'lib/shifty/roster.rb', line 9

def initialize(workers = [])
  @workers = []
  workers.each do |worker|
    push worker
  end
end

Instance Attribute Details

#workersObject (readonly)

Returns the value of attribute workers.



7
8
9
# File 'lib/shifty/roster.rb', line 7

def workers
  @workers
end

Instance Method Details

#popObject



26
27
28
29
30
# File 'lib/shifty/roster.rb', line 26

def pop
  workers.pop.tap do |popped|
    popped.supply = nil
  end
end

#push(worker) ⇒ Object Also known as: <<



18
19
20
21
22
23
# File 'lib/shifty/roster.rb', line 18

def push(worker)
  if worker
    worker.supply = workers.last unless workers.empty?
    workers << worker
  end
end

#shiftObject



32
33
34
35
36
# File 'lib/shifty/roster.rb', line 32

def shift
  workers.shift.tap do
    workers.first.supply = nil
  end
end

#unshift(worker) ⇒ Object



38
39
40
41
# File 'lib/shifty/roster.rb', line 38

def unshift(worker)
  workers.first.supply = worker
  workers.unshift worker
end