Class: PgTrigger::IndentedString

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_trigger/indented_string.rb

Instance Method Summary collapse

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

#newlineObject



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_sObject 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