Class: JsonProjection::Fifo
- Inherits:
-
Object
- Object
- JsonProjection::Fifo
- Defined in:
- lib/json-projection/parser/fifo.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #append(fifo) ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(stack = []) ⇒ Fifo
constructor
A new instance of Fifo.
- #pop ⇒ Object
- #push(val) ⇒ Object
Constructor Details
#initialize(stack = []) ⇒ Fifo
12 13 14 |
# File 'lib/json-projection/parser/fifo.rb', line 12 def initialize(stack = []) @stack = stack end |
Class Method Details
.empty ⇒ Object
4 5 6 |
# File 'lib/json-projection/parser/fifo.rb', line 4 def self.empty @empty ||= self.new end |
.pure(val) ⇒ Object
8 9 10 |
# File 'lib/json-projection/parser/fifo.rb', line 8 def self.pure(val) Fifo.new([val]) end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 |
# File 'lib/json-projection/parser/fifo.rb', line 33 def ==(other) return false unless other.is_a?(Fifo) return stack == other.stack end |
#append(fifo) ⇒ Object
42 43 44 45 46 |
# File 'lib/json-projection/parser/fifo.rb', line 42 def append(fifo) return self if fifo.empty? return fifo if self.empty? Fifo.new(@stack.concat(fifo.stack)) end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/json-projection/parser/fifo.rb', line 29 def empty? @stack.empty? end |
#hash ⇒ Object
38 39 40 |
# File 'lib/json-projection/parser/fifo.rb', line 38 def hash stack.hash end |
#pop ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/json-projection/parser/fifo.rb', line 20 def pop() return self, nil if empty? init = @stack.slice(0, @stack.size - 1) last = @stack.last return Fifo.new(init), last end |
#push(val) ⇒ Object
16 17 18 |
# File 'lib/json-projection/parser/fifo.rb', line 16 def push(val) Fifo.new(@stack.dup.insert(0, val)) end |