Sha256: f1a1582c896cf09692d7cdfa934eadb3e0a8684858d62b24caa6ccf4718b4f4c

Contents?: true

Size: 791 Bytes

Versions: 16

Compression:

Stored size: 791 Bytes

Contents

module FN
  module SWF
    class Struct < Hash
      TAB = "  "
      
      attr_reader :buffer 
      
      def initialize
        @buffer = ""
        @indent_level = 0
      end
      
      def break
        self << ""
      end
      
      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
      
      def tabs
        TAB * @indent_level
      end
      
      def indent
        @indent_level += 1
        if block_given?
          yield
          @indent_level -= 1
        end
      end
      
      def undent
        @indent_level -= 1
        raise "can't indent < 0"          if @indent_level < 0
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fn_document-0.9.18 lib/fn/swf/struct.rb
fn_document-0.9.17 lib/fn/swf/struct.rb
fn_document-0.9.16 lib/fn/swf/struct.rb
fn_document-0.9.15 lib/fn/swf/struct.rb
fn_document-0.9.14 lib/fn/swf/struct.rb
fn_document-0.9.13 lib/fn/swf/struct.rb
fn_document-0.9.12 lib/fn/swf/struct.rb
fn_document-0.9.11 lib/fn/swf/struct.rb
fn_document-0.9.10 lib/fn/swf/struct.rb
fn_document-0.9.9 lib/fn/swf/struct.rb
fn_document-0.9.8 lib/fn/swf/struct.rb
fn_document-0.9.7 lib/fn/swf/struct.rb
fn_document-0.9.6 lib/fn/swf/struct.rb
fn_document-0.9.4 lib/fn/swf/struct.rb
fn_document-0.9.3 lib/fn/swf/struct.rb
fn_document-0.9.2 lib/fn/swf/struct.rb