Class: Temill::Emitters::Printer
- Inherits:
-
Object
- Object
- Temill::Emitters::Printer
- Defined in:
- lib/temill/emitter.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#output_lines ⇒ Object
readonly
Returns the value of attribute output_lines.
Instance Method Summary collapse
-
#initialize(io = $stdout, **options) ⇒ Printer
constructor
A new instance of Printer.
- #lineno ⇒ Object
- #obj_to_s(obj) ⇒ Object
- #out(str) ⇒ Object
- #out_nl(str = nil) ⇒ Object
- #print(obj) ⇒ Object
- #print_empty_line ⇒ Object
- #print_raw(str) ⇒ Object
- #print_str(str) ⇒ Object
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, **) = @output_lines = 0 @indent = '' @io = io end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
106 107 108 |
# File 'lib/temill/emitter.rb', line 106 def indent @indent end |
#output_lines ⇒ Object (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
#lineno ⇒ Object
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 = [: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 |
#print(obj) ⇒ Object
130 131 132 |
# File 'lib/temill/emitter.rb', line 130 def print(obj) print_str(obj_to_s(obj)) end |
#print_empty_line ⇒ Object
142 143 144 145 |
# File 'lib/temill/emitter.rb', line 142 def print_empty_line out @indent out_nl '#' end |
#print_raw(str) ⇒ Object
147 148 149 150 151 |
# File 'lib/temill/emitter.rb', line 147 def print_raw(str) str.each_line{| line | out_nl line } end |
#print_str(str) ⇒ Object
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 |