Class: RgGen::OutputBase::CodeBlock
- Inherits:
-
Object
- Object
- RgGen::OutputBase::CodeBlock
- Defined in:
- lib/rggen/output_base/code_block.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
Instance Method Summary collapse
- #<<(other) ⇒ Object
-
#initialize ⇒ CodeBlock
constructor
A new instance of CodeBlock.
- #last_line_empty? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CodeBlock
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
#indent ⇒ Object
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
31 32 33 |
# File 'lib/rggen/output_base/code_block.rb', line 31 def last_line_empty? lines.empty? || lines.last.empty? end |
#to_s ⇒ Object
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 |