Class: PDoc::Fragment
- Inherits:
-
Object
show all
- Defined in:
- lib/pdoc/parser/fragment.rb
Defined Under Namespace
Classes: InconsistentPrefixError
Constant Summary
collapse
- PREFIX_REGEXP =
/^\s*\*?\s*/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(string, line_number) ⇒ Fragment
Returns a new instance of Fragment.
8
9
10
11
|
# File 'lib/pdoc/parser/fragment.rb', line 8
def initialize(string, line_number)
@line_number = line_number
@string = string
end
|
Instance Attribute Details
#line_number ⇒ Object
Returns the value of attribute line_number.
7
8
9
|
# File 'lib/pdoc/parser/fragment.rb', line 7
def line_number
@line_number
end
|
Instance Method Details
#lines ⇒ Object
41
42
43
|
# File 'lib/pdoc/parser/fragment.rb', line 41
def lines
@lines ||= @string.split("\n")
end
|
#normalize ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/pdoc/parser/fragment.rb', line 13
def normalize
results = []
lines.each_with_index do |line, index|
if index == 0 results << line.sub(/\s*\/\*\*\s*/, '') elsif index == lines.size - 1 results << line.sub(/\s*\*\*?\/\s*/, '') elsif line =~ prefix_regexp results << line.sub(prefix_regexp, '') else
raise InconsistentPrefixError.new(self, line, index)
end
end
results
end
|
#prefix ⇒ Object
33
34
35
|
# File 'lib/pdoc/parser/fragment.rb', line 33
def prefix
PREFIX_REGEXP.match(lines[1])[0] if lines.size > 2
end
|
#prefix_regexp ⇒ Object
37
38
39
|
# File 'lib/pdoc/parser/fragment.rb', line 37
def prefix_regexp
@prefix_regexp ||= Regexp.new('^' << Regexp.escape(prefix))
end
|