Class: FloorManager::Queue
- Inherits:
-
Object
- Object
- FloorManager::Queue
- Includes:
- Enumerable
- Defined in:
- lib/floormanager/queue.rb
Instance Method Summary collapse
-
#[] ⇒ Object
Get an item in the queue.
-
#add(item) ⇒ Object
(also: #<<)
Add an item to the queue.
-
#checked_out ⇒ Object
Get checked out items.
-
#checkin(item, state = States::SUCCESS) ⇒ Object
Check in an item with a new value, optionally with a state (which defaults to SUCCESS).
-
#checkout ⇒ Object
Check out an item from the queue.
-
#completed ⇒ Object
Get completed items.
-
#done? ⇒ Boolean
Is the queue done?.
-
#each ⇒ Object
Returns each item with value, hash style.
-
#failed ⇒ Object
Get failed items.
-
#initialize(*args) ⇒ Queue
constructor
A new instance of Queue.
-
#length ⇒ Object
Total queue length.
-
#pending ⇒ Object
Get pending items.
-
#pending? ⇒ Boolean
Does this queue have pending items?.
-
#successed ⇒ Object
Get successed items.
Constructor Details
#initialize(*args) ⇒ Queue
Returns a new instance of Queue.
5 6 7 8 |
# File 'lib/floormanager/queue.rb', line 5 def initialize(*args) @queue = [] args.each{|a| self << a} if (args = *args) end |
Instance Method Details
#[] ⇒ Object
Get an item in the queue
27 28 29 |
# File 'lib/floormanager/queue.rb', line 27 def get_item(index) @queue[index] end |
#add(item) ⇒ Object Also known as: <<
Add an item to the queue
13 14 15 16 17 18 19 20 |
# File 'lib/floormanager/queue.rb', line 13 def add(item) @queue << { :item => item, :value => nil, :state => States::PENDING, :index => @queue.length } end |
#checked_out ⇒ Object
Get checked out items
76 77 78 |
# File 'lib/floormanager/queue.rb', line 76 def checked_out checked_out_items.map{|i| i[:item]} end |
#checkin(item, state = States::SUCCESS) ⇒ Object
Check in an item with a new value, optionally with a state (which defaults to SUCCESS)
47 48 49 50 51 52 53 |
# File 'lib/floormanager/queue.rb', line 47 def checkin(item, state=States::SUCCESS) if item.kind_of?(Hash) && @queue[item[:index]][:item] == item[:item] @queue[item[:index]] = item.merge({:state => state}) else invalid_item! end end |
#checkout ⇒ Object
Check out an item from the queue
35 36 37 38 39 40 41 42 43 |
# File 'lib/floormanager/queue.rb', line 35 def checkout if pending? item = pending_items.first item[:state] = States::CHECKED_OUT item else nil end end |
#completed ⇒ Object
Get completed items
81 82 83 |
# File 'lib/floormanager/queue.rb', line 81 def completed completed_items.map{|i| i[:item]} end |
#done? ⇒ Boolean
Is the queue done?
61 62 63 |
# File 'lib/floormanager/queue.rb', line 61 def done? (pending.length == 0 && checked_out.length == 0) ? true : false end |
#each ⇒ Object
Returns each item with value, hash style
30 31 32 |
# File 'lib/floormanager/queue.rb', line 30 def each @queue.each{|item| yield item[:item], item[:value]} end |
#failed ⇒ Object
Get failed items
91 92 93 |
# File 'lib/floormanager/queue.rb', line 91 def failed failed_items.map{|i| i[:item]} end |
#length ⇒ Object
Total queue length
56 57 58 |
# File 'lib/floormanager/queue.rb', line 56 def length @queue.length end |
#pending ⇒ Object
Get pending items
71 72 73 |
# File 'lib/floormanager/queue.rb', line 71 def pending pending_items.map{|i| i[:item]} end |
#pending? ⇒ Boolean
Does this queue have pending items?
66 67 68 |
# File 'lib/floormanager/queue.rb', line 66 def pending? (pending.length > 0) ? true : false end |
#successed ⇒ Object
Get successed items
86 87 88 |
# File 'lib/floormanager/queue.rb', line 86 def successed successed_items.map{|i| i[:item]} end |