Class: ToSource::State
- Inherits:
-
Object
- Object
- ToSource::State
- Defined in:
- lib/to_source/state.rb
Overview
Emitter state
Instance Attribute Summary collapse
-
#buffer ⇒ Array
readonly
private
Return buffer.
-
#identation ⇒ Fixnum
readonly
private
Return current indentation level.
-
#last ⇒ Command
readonly
private
Return last command.
Instance Method Summary collapse
-
#blank? ⇒ true, false
private
Test for blank line.
-
#execute(command) ⇒ self
private
Execute command.
-
#indent ⇒ self
private
Indent line if needed.
-
#initialize ⇒ undefined
constructor
private
Initialize object.
-
#new_line ⇒ self
private
Write newline.
-
#push(command) ⇒ self
private
Push command.
-
#shift(width) ⇒ self
private
Perform shift by width.
-
#source ⇒ String
private
Return source.
-
#write(string) ⇒ self
private
Write string to buffer.
Constructor Details
#initialize ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
35 36 37 38 39 |
# File 'lib/to_source/state.rb', line 35 def initialize @last = Command::NULL @indentation = 0 @buffer = [] end |
Instance Attribute Details
#buffer ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return buffer
27 28 29 |
# File 'lib/to_source/state.rb', line 27 def buffer @buffer end |
#identation ⇒ Fixnum (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return current indentation level
19 20 21 |
# File 'lib/to_source/state.rb', line 19 def identation @identation end |
#last ⇒ Command (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return last command
11 12 13 |
# File 'lib/to_source/state.rb', line 11 def last @last end |
Instance Method Details
#blank? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test for blank line
114 115 116 |
# File 'lib/to_source/state.rb', line 114 def blank? buffer.last == "\n" end |
#execute(command) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute command
49 50 51 52 53 |
# File 'lib/to_source/state.rb', line 49 def execute(command) command.run(self) @last = command self end |
#indent ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indent line if needed
98 99 100 101 102 |
# File 'lib/to_source/state.rb', line 98 def indent return unless blank? write(' ' * @indentation) self end |
#new_line ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write newline
124 125 126 127 |
# File 'lib/to_source/state.rb', line 124 def new_line write("\n") self end |
#push(command) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Push command
86 87 88 89 90 |
# File 'lib/to_source/state.rb', line 86 def push(command) indent write(command.content) self end |
#shift(width) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform shift by width
137 138 139 140 141 |
# File 'lib/to_source/state.rb', line 137 def shift(width) @indentation += width @indentation = 0 if @indentation < 0 new_line end |
#source ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return source
74 75 76 |
# File 'lib/to_source/state.rb', line 74 def source buffer.join('') end |
#write(string) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write string to buffer
63 64 65 66 |
# File 'lib/to_source/state.rb', line 63 def write(string) @buffer << string self end |