Class: PgTrigger::IndentedString
- Inherits:
-
Object
- Object
- PgTrigger::IndentedString
- Defined in:
- lib/pg_trigger/indented_string.rb
Instance Method Summary collapse
- #+(str) ⇒ Object
- #append(str) ⇒ Object (also: #<<)
- #indent! ⇒ Object
-
#initialize(size:, initial_indent: true) ⇒ IndentedString
constructor
A new instance of IndentedString.
- #newline ⇒ Object
- #outdent! ⇒ Object
-
#to_s ⇒ Object
(also: #to_str)
def endline @inner << ānā self end.
Constructor Details
#initialize(size:, initial_indent: true) ⇒ IndentedString
Returns a new instance of IndentedString.
4 5 6 7 8 |
# File 'lib/pg_trigger/indented_string.rb', line 4 def initialize(size:, initial_indent: true) @spaces = " " * size @inner = +"" @start = initial_indent end |
Instance Method Details
#+(str) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pg_trigger/indented_string.rb', line 24 def +(str) str.each_line do |l| if l == "\n" @inner << l else @inner << @spaces << l end end self end |
#append(str) ⇒ Object Also known as: <<
18 19 20 21 |
# File 'lib/pg_trigger/indented_string.rb', line 18 def append(str) @inner << @spaces << str self end |
#indent! ⇒ Object
10 11 12 |
# File 'lib/pg_trigger/indented_string.rb', line 10 def indent! @spaces << " " end |
#newline ⇒ Object
35 36 37 |
# File 'lib/pg_trigger/indented_string.rb', line 35 def newline @inner << "\n" end |
#outdent! ⇒ Object
14 15 16 |
# File 'lib/pg_trigger/indented_string.rb', line 14 def outdent! @spaces.slice!(-2, 2) end |
#to_s ⇒ Object Also known as: to_str
def endline
@inner << "\n"
self
end
55 |
# File 'lib/pg_trigger/indented_string.rb', line 55 def to_s = @inner |