Class: SM::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/markup/simple_markup/lines.rb

Constant Summary collapse

INFINITY =
9999
BLANK =
:BLANK
HEADING =
:HEADING
LIST =
:LIST
RULE =
:RULE
PARAGRAPH =
:PARAGRAPH
VERBATIM =
:VERBATIM

Instance Attribute Summary collapse

Instance Method Summary collapse

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/markup/simple_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

#deletedObject

true if this line has been deleted from the list of lines



39
40
41
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 39

def deleted
  @deleted
end

#flagObject

A flag. For list lines, this is the type of the list



33
34
35
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 33

def flag
  @flag
end

#leading_spacesObject

the number of leading spaces



36
37
38
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 36

def leading_spaces
  @leading_spaces
end

#levelObject

The indentation nesting level



23
24
25
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 23

def level
  @level
end

#paramObject

A prefix or parameter. For LIST lines, this is the text that introduced the list item (the label)



30
31
32
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 30

def param
  @param
end

#textObject

The contents



26
27
28
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 26

def text
  @text
end

#typeObject

line type



20
21
22
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 20

def type
  @type
end

Instance Method Details

#isBlank?Boolean

Return true if this line is blank

Returns:

  • (Boolean)


62
63
64
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 62

def isBlank?
  @text.length.zero?
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/markup/simple_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



75
76
77
78
79
80
81
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 75

def strip_leading(size)
  if @text.size > size
    @text[0,size] = ""
  else
    @text = ""
  end
end

#to_sObject



83
84
85
# File 'lib/rdoc/markup/simple_markup/lines.rb', line 83

def to_s
  "#@type#@level: #@text"
end