Class: Eggshell::Line
- Inherits:
-
Object
- Object
- Eggshell::Line
- 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
-
#indent_lvl ⇒ Object
readonly
Returns the value of attribute indent_lvl.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#line_num ⇒ Object
readonly
Returns the value of attribute line_num.
-
#tab_str ⇒ Object
readonly
Returns the value of attribute tab_str.
Instance Method Summary collapse
-
#initialize(line, tab_str, indent_lvl, line_num, raw = nil) ⇒ Line
constructor
A new instance of Line.
- #match(regex) ⇒ Object
- #raw ⇒ Object
-
#replace(line, raw = nil) ⇒ Object
Creates a new instance of this line, replacing the actual contents with the supplied line.
-
#to_s ⇒ Object
Returns the raw line with indents.
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_lvl ⇒ Object (readonly)
Returns the value of attribute indent_lvl.
36 37 38 |
# File 'lib/eggshell.rb', line 36 def indent_lvl @indent_lvl end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
36 37 38 |
# File 'lib/eggshell.rb', line 36 def line @line end |
#line_num ⇒ Object (readonly)
Returns the value of attribute line_num.
36 37 38 |
# File 'lib/eggshell.rb', line 36 def line_num @line_num end |
#tab_str ⇒ Object (readonly)
Returns the value of attribute tab_str.
36 37 38 |
# File 'lib/eggshell.rb', line 36 def tab_str @tab_str end |
Instance Method Details
#match(regex) ⇒ Object
32 33 34 |
# File 'lib/eggshell.rb', line 32 def match(regex) @line.match(regex) end |
#raw ⇒ Object
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_s ⇒ Object
Returns the raw line with indents.
19 20 21 |
# File 'lib/eggshell.rb', line 19 def to_s "#{@tab_str*@indent_lvl}#{@line}" end |