Class: Xdrgen::OutputFile
- Inherits:
-
Object
- Object
- Xdrgen::OutputFile
- Defined in:
- lib/xdrgen/output_file.rb
Constant Summary collapse
- SPACES_PER_INDENT =
2
Instance Method Summary collapse
- #balance_after(balance_regex, include_space = false) ⇒ Object
- #break ⇒ Object
- #close ⇒ Object
- #indent(step = 1) ⇒ Object
-
#initialize(path) ⇒ OutputFile
constructor
A new instance of OutputFile.
- #puts(s = "") ⇒ Object
- #unbreak ⇒ Object
Constructor Details
#initialize(path) ⇒ OutputFile
Returns a new instance of OutputFile.
6 7 8 9 10 11 12 |
# File 'lib/xdrgen/output_file.rb', line 6 def initialize(path) @path = path @current_indent = 0 FileUtils.mkdir_p File.dirname(@path) @io = File.open(@path, 'w') end |
Instance Method Details
#balance_after(balance_regex, include_space = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xdrgen/output_file.rb', line 38 def balance_after(balance_regex, include_space=false) @old_io = @io @io = StringIO.new yield raw = @io.string @old_io.puts balance_string(raw, balance_regex, include_space) ensure @io = @old_io @old_io = nil end |
#break ⇒ Object
30 31 32 |
# File 'lib/xdrgen/output_file.rb', line 30 def break @break_needed = true end |
#close ⇒ Object
14 15 16 |
# File 'lib/xdrgen/output_file.rb', line 14 def close @io.close end |
#indent(step = 1) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/xdrgen/output_file.rb', line 23 def indent(step=1) @current_indent += step yield ensure @current_indent -= step end |
#puts(s = "") ⇒ Object
18 19 20 21 |
# File 'lib/xdrgen/output_file.rb', line 18 def puts(s="") write_break_if_needed @io.puts indented(s) end |
#unbreak ⇒ Object
34 35 36 |
# File 'lib/xdrgen/output_file.rb', line 34 def unbreak @break_needed = false end |