Class: RDocF95::Markup::Line
- Inherits:
-
Object
- Object
- RDocF95::Markup::Line
- Defined in:
- lib/rdoc-f95/markup/lines.rb
Overview
We store the lines we’re working on as objects of class Line. These contain the text of the line, along with a flag indicating the line type, and an indentation level.
Constant Summary collapse
- INFINITY =
9999
- LINE_TYPES =
[ :BLANK, :HEADING, :LIST, :PARAGRAPH, :RULE, :VERBATIM, ]
Instance Attribute Summary collapse
-
#deleted ⇒ Object
true if this line has been deleted from the list of lines.
-
#flag ⇒ Object
A flag.
-
#leading_spaces ⇒ Object
the number of leading spaces.
-
#level ⇒ Object
The indentation nesting level.
-
#param ⇒ Object
A prefix or parameter.
-
#text ⇒ Object
The contents.
-
#type ⇒ Object
line type.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Return true if this line is blank.
-
#initialize(text) ⇒ Line
constructor
A new instance of Line.
-
#stamp(type, level, param = "", flag = nil) ⇒ Object
stamp a line with a type, a level, a prefix, and a flag.
-
#strip_leading(size) ⇒ Object
Strip off the leading margin.
- #to_s ⇒ Object
Constructor Details
#initialize(text) ⇒ Line
Returns a new instance of Line.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rdoc-f95/markup/lines.rb', line 42 def initialize(text) @text = text.dup @deleted = false # expand tabs 1 while @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)} && $~ #` # Strip trailing whitespace @text.sub!(/\s+$/, '') # and look for leading whitespace if @text.length > 0 @text =~ /^(\s*)/ @leading_spaces = $1.length else @leading_spaces = INFINITY end end |
Instance Attribute Details
#deleted ⇒ Object
true if this line has been deleted from the list of lines
40 41 42 |
# File 'lib/rdoc-f95/markup/lines.rb', line 40 def deleted @deleted end |
#flag ⇒ Object
A flag. For list lines, this is the type of the list
34 35 36 |
# File 'lib/rdoc-f95/markup/lines.rb', line 34 def flag @flag end |
#leading_spaces ⇒ Object
the number of leading spaces
37 38 39 |
# File 'lib/rdoc-f95/markup/lines.rb', line 37 def leading_spaces @leading_spaces end |
#level ⇒ Object
The indentation nesting level
24 25 26 |
# File 'lib/rdoc-f95/markup/lines.rb', line 24 def level @level end |
#param ⇒ Object
A prefix or parameter. For LIST lines, this is the text that introduced the list item (the label)
31 32 33 |
# File 'lib/rdoc-f95/markup/lines.rb', line 31 def param @param end |
#text ⇒ Object
The contents
27 28 29 |
# File 'lib/rdoc-f95/markup/lines.rb', line 27 def text @text end |
#type ⇒ Object
line type
21 22 23 |
# File 'lib/rdoc-f95/markup/lines.rb', line 21 def type @type end |
Instance Method Details
#blank? ⇒ Boolean
Return true if this line is blank
62 63 64 |
# File 'lib/rdoc-f95/markup/lines.rb', line 62 def blank? @text.empty? end |
#stamp(type, level, param = "", flag = nil) ⇒ Object
stamp a line with a type, a level, a prefix, and a flag
67 68 69 |
# File 'lib/rdoc-f95/markup/lines.rb', line 67 def stamp(type, level, param="", flag=nil) @type, @level, @param, @flag = type, level, param, flag end |
#strip_leading(size) ⇒ Object
Strip off the leading margin
74 75 76 77 78 79 80 |
# File 'lib/rdoc-f95/markup/lines.rb', line 74 def strip_leading(size) if @text.size > size @text[0,size] = "" else @text = "" end end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/rdoc-f95/markup/lines.rb', line 82 def to_s "#@type#@level: #@text" end |