Class: FN::SWF::Struct

Inherits:
Hash
  • Object
show all
Defined in:
lib/fn/swf/struct.rb

Constant Summary collapse

TAB =
"  "

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStruct

Returns a new instance of Struct.



8
9
10
11
# File 'lib/fn/swf/struct.rb', line 8

def initialize
  @buffer = ""
  @indent_level = 0
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



6
7
8
# File 'lib/fn/swf/struct.rb', line 6

def buffer
  @buffer
end

Instance Method Details

#<<(s, omit_end_tag = false, &b) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/fn/swf/struct.rb', line 17

def <<(s, omit_end_tag = false, &b)
  @buffer << "#{tabs}#{s}\n"
  if block_given?
    indent(&b)
    @buffer << "#{tabs}.end\n"      unless omit_end_tag
  end
end

#breakObject



13
14
15
# File 'lib/fn/swf/struct.rb', line 13

def break
  self << ""
end

#indentObject



29
30
31
32
33
34
35
# File 'lib/fn/swf/struct.rb', line 29

def indent
  @indent_level += 1
  if block_given?
    yield
    @indent_level -= 1
  end
end

#tabsObject



25
26
27
# File 'lib/fn/swf/struct.rb', line 25

def tabs
  TAB * @indent_level
end

#undentObject



37
38
39
40
# File 'lib/fn/swf/struct.rb', line 37

def undent
  @indent_level -= 1
  raise "can't indent < 0"          if @indent_level < 0
end