JSQueue 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/js_queue.rb +28 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ec8036ff7e1adf1dee14b9bfb7e2916a82f3bed
4
- data.tar.gz: 405d1ba43932527c1e54ea1ea2fadb2059f4d9ea
3
+ metadata.gz: 4a77f351086b55cbfdf216ab768fa0ca077d99a6
4
+ data.tar.gz: fa14fd8c07d7df933da37ba2f9ba106b8d5c8a27
5
5
  SHA512:
6
- metadata.gz: c760df615eb8930ab0199fdae960d97c600003e61d727e42bb7c57a355e1ce650d068ceb4c443c7bf70f6286744f283b3c7802292a2728b8f72547fd4f2130d3
7
- data.tar.gz: 0f2d413c3c5d944196e2b76ceee75fdc1d2bdba8ed424131350bab8cd7def9a3cd6641f8d28589ad0470fbdcb829cf99ff963628362c94f3884e70116bb12e23
6
+ metadata.gz: 461c4b61f32090cfc175004809b8093390efbfefe7e1b26d4350f4b901f38a6eb949bef3b27ef4bf715824d8fa24d031b6be044f0f3655c352b2afdca3396a30
7
+ data.tar.gz: b931f3ff762c8c8b682573ae2eb5d0f847d049a3c889f9e4a79e94e90208f1bc3fe239bc157c935ffa6a7d5e3aadb6d8e771ba6b467b2349e8ae436c65b1a839
data/lib/js_queue.rb CHANGED
@@ -3,11 +3,22 @@ require_relative 'queue_node'
3
3
  class JSQueue
4
4
  attr_accessor :first, :last
5
5
 
6
- def initialize(data)
7
- @first = QueueNode.new data
6
+ ##
7
+ # Creates a new queue with an optional first item +data+.
8
+ #
9
+ # If an initial value is provided, it will be considered both the +first+ and
10
+ # +last+ item in the queue.
11
+ def initialize(data=nil)
12
+ @first = QueueNode.new data unless data.nil?
13
+ @first ||= nil
8
14
  @last = @first
9
15
  end
10
16
 
17
+ ##
18
+ # Adds the provided value +data+ to the back of the queue.
19
+ #
20
+ # If it is the only item in the queue, it will be considered both the +first+
21
+ # and the +last+.
11
22
  def enqueue(data)
12
23
  node = QueueNode.new data
13
24
  unless last.nil?
@@ -17,6 +28,11 @@ class JSQueue
17
28
  @first = node if @first.nil?
18
29
  end
19
30
 
31
+ ##
32
+ # Removes and returns the data value of the +first+ item in the queue.
33
+ #
34
+ # == Example
35
+ # queue.dequeue # => 'I was first in line'
20
36
  def dequeue
21
37
  return if @first.nil?
22
38
  data = @first.data
@@ -25,10 +41,20 @@ class JSQueue
25
41
  data
26
42
  end
27
43
 
44
+ ##
45
+ # Returns the +first+ enqueued item's value, without removing it.
46
+ #
47
+ # == Example
48
+ # queue.peek # => 'I am first in line'
28
49
  def peek
29
50
  first.nil? ? nil : first.data
30
51
  end
31
52
 
53
+ ##
54
+ # Returns a Boolean indicating whether the queue has any items.
55
+ #
56
+ # == Example
57
+ # queue.empty? # => false
32
58
  def empty?
33
59
  first.nil?
34
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: JSQueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Saint Jacque