Class: TTYHue::Parser::ColorStack
- Inherits:
-
Object
- Object
- TTYHue::Parser::ColorStack
- Defined in:
- lib/ttyhue/parser/color_stack.rb
Instance Method Summary collapse
-
#initialize ⇒ ColorStack
constructor
A new instance of ColorStack.
- #pop(value, opts = {}) ⇒ Object
- #push(value, opts = {}) ⇒ Object
- #top(opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ ColorStack
Returns a new instance of ColorStack.
5 6 7 |
# File 'lib/ttyhue/parser/color_stack.rb', line 5 def initialize @stack = [] end |
Instance Method Details
#pop(value, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ttyhue/parser/color_stack.rb', line 13 def pop(value, opts={}) @stack.each_with_index do |v,i| if v[:value] == value && v[:opts] == opts @stack.delete_at(i) break end end end |
#push(value, opts = {}) ⇒ Object
9 10 11 |
# File 'lib/ttyhue/parser/color_stack.rb', line 9 def push(value, opts={}) @stack.unshift({value: value, opts: opts}) end |
#top(opts = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/ttyhue/parser/color_stack.rb', line 22 def top(opts={}) @stack.select do |e| e[:opts] == opts end.first.to_h[:value] end |