Class: Temill::Emitters::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/temill/emitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = $stdout, **options) ⇒ Printer

Returns a new instance of Printer.



108
109
110
111
112
113
# File 'lib/temill/emitter.rb', line 108

def initialize(io = $stdout, **options)
  @options = options
  @output_lines = 0
  @indent = ''
  @io = io
end

Instance Attribute Details

#indentObject

Returns the value of attribute indent.



106
107
108
# File 'lib/temill/emitter.rb', line 106

def indent
  @indent
end

#output_linesObject (readonly)

Returns the value of attribute output_lines.



105
106
107
# File 'lib/temill/emitter.rb', line 105

def output_lines
  @output_lines
end

Instance Method Details

#linenoObject



115
116
117
# File 'lib/temill/emitter.rb', line 115

def lineno
  @output_lines + 1
end

#obj_to_s(obj) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/temill/emitter.rb', line 119

def obj_to_s(obj)
  case f = @options[:inspect]
  when Symbol
    obj.__send__(f)
  when nil
    obj.pretty_inspect
  else
    f.call(obj)
  end
end

#out(str) ⇒ Object



153
154
155
156
# File 'lib/temill/emitter.rb', line 153

def out(str)
  @io.print(str)
  self
end

#out_nl(str = nil) ⇒ Object



158
159
160
161
162
# File 'lib/temill/emitter.rb', line 158

def out_nl(str=nil)
  @io.puts(str)
  @output_lines += 1
  self
end


130
131
132
# File 'lib/temill/emitter.rb', line 130

def print(obj)
  print_str(obj_to_s(obj))
end


142
143
144
145
# File 'lib/temill/emitter.rb', line 142

def print_empty_line
  out @indent
  out_nl '#'
end


147
148
149
150
151
# File 'lib/temill/emitter.rb', line 147

def print_raw(str)
  str.each_line{| line |
    out_nl line
  }
end


134
135
136
137
138
139
140
# File 'lib/temill/emitter.rb', line 134

def print_str(str)
  str.each_line{| line |
    out @indent
    out '# '
    out_nl line
  }
end