Class: Bijou::Stack

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeStack

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

#bufferObject (readonly)

Returns the value of attribute buffer.



38
39
40
# File 'lib/bijou/context.rb', line 38

def buffer
  @buffer
end

#framesObject (readonly)

Returns the value of attribute frames.



39
40
41
# File 'lib/bijou/context.rb', line 39

def frames
  @frames
end

Instance Method Details

#flushObject



94
95
96
97
98
# File 'lib/bijou/context.rb', line 94

def flush
  s = @buffer
  @buffer = ''
  s
end

#flush_frameObject



80
81
82
# File 'lib/bijou/context.rb', line 80

def flush_frame()
  @buffer << top_frame.flush
end

#indexObject



41
42
43
# File 'lib/bijou/context.rb', line 41

def index
  @frame_index
end

#next_frameObject



71
72
73
74
# File 'lib/bijou/context.rb', line 71

def next_frame
  @frame_index -= 1
  top_frame
end

#outputObject



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_frameObject



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

#startObject



63
64
65
# File 'lib/bijou/context.rb', line 63

def start
  @frame_index = @frames.length - 1
end

#to_sObject



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_frameObject



67
68
69
# File 'lib/bijou/context.rb', line 67

def top_frame
  @frames[@frame_index]
end