Class: RelatonIso::Queue
- Inherits:
-
Object
- Object
- RelatonIso::Queue
- Extended by:
- Forwardable
- Defined in:
- lib/relaton_iso/queue.rb
Overview
Queue of links to fetch.
Constant Summary collapse
- FILE =
"iso-queue.txt".freeze
Instance Method Summary collapse
-
#add_first(item) ⇒ void
Add item to queue at first position if it is not already there.
-
#move_last(item) ⇒ void
Move or add item to the end of the queue.
-
#queue ⇒ Array<String>
Open queue file if exist.
-
#save ⇒ void
Save queue to file.
Instance Method Details
#add_first(item) ⇒ void
This method returns an undefined value.
Add item to queue at first position if it is not already there.
27 28 29 |
# File 'lib/relaton_iso/queue.rb', line 27 def add_first(item) queue.unshift item unless queue.include? item end |
#move_last(item) ⇒ void
This method returns an undefined value.
Move or add item to the end of the queue.
38 39 40 41 |
# File 'lib/relaton_iso/queue.rb', line 38 def move_last(item) queue.delete item queue << item end |
#queue ⇒ Array<String>
Open queue file if exist. If not, create new empty queue.
16 17 18 |
# File 'lib/relaton_iso/queue.rb', line 16 def queue @queue ||= File.exist?(FILE) ? File.read(FILE).split("\n") : [] end |
#save ⇒ void
This method returns an undefined value.
Save queue to file.
57 58 59 |
# File 'lib/relaton_iso/queue.rb', line 57 def save File.write FILE, queue.to_a.join("\n") end |