Class: ToSource::State
- Inherits:
-
Object
- Object
- ToSource::State
- Defined in:
- lib/to_source/state.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#identation ⇒ Object
readonly
Returns the value of attribute identation.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #execute(command) ⇒ Object
- #indent ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #last_keyword? ⇒ Boolean
- #new_line ⇒ Object
- #push(command) ⇒ Object
- #shift(width) ⇒ Object
- #source ⇒ Object
- #space ⇒ Object
- #write(string) ⇒ Object
Constructor Details
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
6 7 8 |
# File 'lib/to_source/state.rb', line 6 def buffer @buffer end |
#identation ⇒ Object (readonly)
Returns the value of attribute identation.
5 6 7 |
# File 'lib/to_source/state.rb', line 5 def identation @identation end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
4 5 6 |
# File 'lib/to_source/state.rb', line 4 def last @last end |
Instance Method Details
#blank? ⇒ Boolean
41 42 43 |
# File 'lib/to_source/state.rb', line 41 def blank? buffer.last == "\n" end |
#execute(command) ⇒ Object
14 15 16 17 |
# File 'lib/to_source/state.rb', line 14 def execute(command) command.run(self) @last = command end |
#indent ⇒ Object
36 37 38 39 |
# File 'lib/to_source/state.rb', line 36 def indent return unless blank? write(' ' * @indentation) end |
#last_keyword? ⇒ Boolean
19 20 21 |
# File 'lib/to_source/state.rb', line 19 def last_keyword? last.kind_of?(Command::Token::Keyword) end |
#new_line ⇒ Object
45 46 47 |
# File 'lib/to_source/state.rb', line 45 def new_line write("\n") end |
#push(command) ⇒ Object
31 32 33 34 |
# File 'lib/to_source/state.rb', line 31 def push(command) indent write(command.content) end |
#shift(width) ⇒ Object
53 54 55 56 57 |
# File 'lib/to_source/state.rb', line 53 def shift(width) @indentation += width @indentation = 0 if @indentation < 0 new_line end |
#source ⇒ Object
49 50 51 |
# File 'lib/to_source/state.rb', line 49 def source buffer.join('') end |
#space ⇒ Object
27 28 29 |
# File 'lib/to_source/state.rb', line 27 def space write(' ') end |
#write(string) ⇒ Object
23 24 25 |
# File 'lib/to_source/state.rb', line 23 def write(string) @buffer << string end |