Class: RelatonIso::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



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.

Parameters:

  • item (String)

    item to move or add



38
39
40
41
# File 'lib/relaton_iso/queue.rb', line 38

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



16
17
18
# File 'lib/relaton_iso/queue.rb', line 16

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

#savevoid

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