Class: Relaton::Iso::Queue

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • item (String)

    item to add



28
29
30
# File 'lib/relaton/iso/queue.rb', line 28

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.

Parameters:

  • item (String)

    item to move or add



39
40
41
42
# File 'lib/relaton/iso/queue.rb', line 39

def move_last(item)
  queue.delete item
  queue << item
end

#queueArray<String>

Open queue file if exist. If not, create new empty queue.

Returns:

  • (Array<String>)

    queue



17
18
19
# File 'lib/relaton/iso/queue.rb', line 17

def queue
  @queue ||= File.exist?(FILE) ? File.read(FILE).split("\n") : []
end

#savevoid

This method returns an undefined value.

Save queue to file.



58
59
60
# File 'lib/relaton/iso/queue.rb', line 58

def save
  File.write FILE, queue.to_a.join("\n")
end