Class: Lisp::Format::Output

Inherits:
Object show all
Defined in:
lib/carat/lisp-format.rb

Overview

Represents output for a State object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = '', col = 0) ⇒ Output

Create a new Output object.



111
112
113
# File 'lib/carat/lisp-format.rb', line 111

def initialize(str = '', col = 0)
  @output, @col = str, col
end

Instance Attribute Details

#colObject

The current output column.



137
138
139
# File 'lib/carat/lisp-format.rb', line 137

def col
  @col
end

Instance Method Details

#<<(str) ⇒ Object

Add str to the output.



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/carat/lisp-format.rb', line 116

def <<(str)
  if str.is_a? Fixnum
    @output << str.chr
    # How should tabs be handled here?  They should perhaps be
    # interpreted as eight (8) characters wide?  This of course depends
    # on where @col is already at (8 - @col % 8).
    @col = str == ?\n ? 0 : @col + 1
  else
    @output << str
    @col += str.length - (str.rindex(?\n) or 0)
  end
end

#to_sObject

Convert this object to its string representation, which is the output gathered so far. TODO: this is rather silly



132
133
134
# File 'lib/carat/lisp-format.rb', line 132

def to_s
  @output
end