Method: Lazydoc::Utils.scan
- Defined in:
- lib/lazydoc/utils.rb
.scan(line) ⇒ Object
Scan determines if and how to add a line fragment to a comment and yields the appropriate fragments to the block. Returns true if fragments are yielded and false otherwise.
Content may be built from an array of lines using scan like so:
lines = [
"# comments spanning multiple",
"# lines are collected",
"#",
"# while indented lines",
"# are preserved individually",
"# ",
"not a comment line",
"# skipped since the loop breaks",
"# at the first non-comment line"]
c = Comment.new
lines.each do |line|
break unless Utils.scan(line) do |fragment|
c.push(fragment)
end
end
c.content
# => [
# ['comments spanning multiple', 'lines are collected'],
# [''],
# [' while indented lines'],
# [' are preserved individually'],
# [''],
# []]
58 59 60 61 62 63 64 |
# File 'lib/lazydoc/utils.rb', line 58 def scan(line) # :yields: fragment return false unless line =~ /^[ \t]*#[ \t]?(([ \t]*).*?)\r?$/ categorize($1, $2) do |fragment| yield(fragment) end true end |