Class: RgGen::OutputBase::CodeBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/output_base/code_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCodeBlock

Returns a new instance of CodeBlock.



4
5
6
7
8
# File 'lib/rggen/output_base/code_block.rb', line 4

def initialize
  @lines  = []
  @indent = 0
  add_newline
end

Instance Attribute Details

#indentObject

Returns the value of attribute indent.



10
11
12
# File 'lib/rggen/output_base/code_block.rb', line 10

def indent
  @indent
end

Instance Method Details

#<<(other) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rggen/output_base/code_block.rb', line 17

def <<(other)
  case other
  when CodeBlock
    merge_code_block(other)
  when /\n/
    add_multiple_lines_string(other)
  when :newline
    add_newline
  else
    @lines.last << other
  end
  self
end

#last_line_empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rggen/output_base/code_block.rb', line 31

def last_line_empty?
  lines.empty? || lines.last.empty?
end

#to_sObject



35
36
37
# File 'lib/rggen/output_base/code_block.rb', line 35

def to_s
  @lines.map(&:to_s).each(&:rstrip!).join("\n")
end