Class: Bijou::Stack
- Inherits:
-
Object
- Object
- Bijou::Stack
- Defined in:
- lib/bijou/context.rb
Overview
Each comonent/container chain is represented by a Stack object. The stack class contains a list of Frame objects and an output buffer.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
Instance Method Summary collapse
- #flush ⇒ Object
- #flush_frame ⇒ Object
- #index ⇒ Object
-
#initialize ⇒ Stack
constructor
A new instance of Stack.
- #next_frame ⇒ Object
- #output ⇒ Object
- #peek_frame(offset = 1) ⇒ Object
- #pop_frame ⇒ Object
- #push_frame(component) ⇒ Object
- #start ⇒ Object
- #to_s ⇒ Object
- #top_frame ⇒ Object
Constructor Details
#initialize ⇒ Stack
Returns a new instance of Stack.
32 33 34 35 36 |
# File 'lib/bijou/context.rb', line 32 def initialize() @frame_index = 0 @frames = [] @buffer = '' end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
38 39 40 |
# File 'lib/bijou/context.rb', line 38 def buffer @buffer end |
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
39 40 41 |
# File 'lib/bijou/context.rb', line 39 def frames @frames end |
Instance Method Details
#flush ⇒ Object
94 95 96 97 98 |
# File 'lib/bijou/context.rb', line 94 def flush s = @buffer @buffer = '' s end |
#flush_frame ⇒ Object
80 81 82 |
# File 'lib/bijou/context.rb', line 80 def flush_frame() @buffer << top_frame.flush end |
#index ⇒ Object
41 42 43 |
# File 'lib/bijou/context.rb', line 41 def index @frame_index end |
#next_frame ⇒ Object
71 72 73 74 |
# File 'lib/bijou/context.rb', line 71 def next_frame @frame_index -= 1 top_frame end |
#output ⇒ Object
90 91 92 |
# File 'lib/bijou/context.rb', line 90 def output @frames[@frame_index].output end |
#peek_frame(offset = 1) ⇒ Object
76 77 78 |
# File 'lib/bijou/context.rb', line 76 def peek_frame(offset = 1) @frames[@frame_index - offset] end |
#pop_frame ⇒ Object
84 85 86 87 88 |
# File 'lib/bijou/context.rb', line 84 def pop_frame() flush_frame() # @buffer << self.output @frames.pop() end |
#push_frame(component) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/bijou/context.rb', line 55 def push_frame(component) if @frames.length > 0 @buffer << @frames[-1].flush end @frames.push(Frame.new(component)) end |
#start ⇒ Object
63 64 65 |
# File 'lib/bijou/context.rb', line 63 def start @frame_index = @frames.length - 1 end |
#to_s ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/bijou/context.rb', line 45 def to_s s = '' @frames.each {|f| s << "'#{f.component}': " s << "'#{f.output}' " } s << " -> '#{@buffer}'" s end |
#top_frame ⇒ Object
67 68 69 |
# File 'lib/bijou/context.rb', line 67 def top_frame @frames[@frame_index] end |