Class: Eggshell::Line

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

Overview

Encapsulates core parts of a line. Handler can use whatever parts are needed to construct final output. Line number is provided for error reporting.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, tab_str, indent_lvl, line_num, raw = nil) ⇒ Line

Returns a new instance of Line.



10
11
12
13
14
15
16
# File 'lib/eggshell.rb', line 10

def initialize(line, tab_str, indent_lvl, line_num, raw = nil)
	@line = line
	@tab_str = tab_str || ''
	@indent_lvl = indent_lvl
	@line_num = line_num
	@raw = raw
end

Instance Attribute Details

#indent_lvlObject (readonly)

Returns the value of attribute indent_lvl.



32
33
34
# File 'lib/eggshell.rb', line 32

def indent_lvl
  @indent_lvl
end

#lineObject (readonly)

Returns the value of attribute line.



32
33
34
# File 'lib/eggshell.rb', line 32

def line
  @line
end

#line_numObject (readonly)

Returns the value of attribute line_num.



32
33
34
# File 'lib/eggshell.rb', line 32

def line_num
  @line_num
end

#tab_strObject (readonly)

Returns the value of attribute tab_str.



32
33
34
# File 'lib/eggshell.rb', line 32

def tab_str
  @tab_str
end

Instance Method Details

#rawObject



23
24
25
# File 'lib/eggshell.rb', line 23

def raw
	@raw ? @raw : to_s
end

#replace(line, raw = nil) ⇒ Object

Creates a new instance of this line, replacing the actual contents with the supplied line.



28
29
30
# File 'lib/eggshell.rb', line 28

def replace(line, raw = nil)
	Line.new(line, @tab_str, @indent_lvl, @line_num, raw)
end

#to_sObject

Returns the raw line with indents.



19
20
21
# File 'lib/eggshell.rb', line 19

def to_s
	"#{@tab_str*@indent_lvl}#{@line}"
end