Class: Camille::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/camille/line.rb

Overview

lines with indentation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, indent = 0) ⇒ Line

Returns a new instance of Line.



6
7
8
9
# File 'lib/camille/line.rb', line 6

def initialize string, indent = 0
  @string = string
  @indent = indent
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



4
5
6
# File 'lib/camille/line.rb', line 4

def indent
  @indent
end

#stringObject (readonly)

Returns the value of attribute string.



4
5
6
# File 'lib/camille/line.rb', line 4

def string
  @string
end

Class Method Details

.join(lines, delimiter) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/camille/line.rb', line 34

def self.join lines, delimiter
  size = lines.size
  lines.each_with_index do |line, index|
    if index < size - 1
      line.append(delimiter)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/camille/line.rb', line 16

def == other
  @string == other.string && @indent == other.indent
end

#append(str) ⇒ Object



25
26
27
28
# File 'lib/camille/line.rb', line 25

def append str
  @string = @string + str
  self
end

#do_indentObject



11
12
13
14
# File 'lib/camille/line.rb', line 11

def do_indent
  @indent += 2
  self
end

#prepend(str) ⇒ Object



20
21
22
23
# File 'lib/camille/line.rb', line 20

def prepend str
  @string = str + @string
  self
end

#to_sObject



30
31
32
# File 'lib/camille/line.rb', line 30

def to_s
  ' ' * @indent + @string
end