Class: JsDuck::Doc::Comment
- Inherits:
-
Object
- Object
- JsDuck::Doc::Comment
- Defined in:
- lib/jsduck/doc/comment.rb
Overview
A simple helper to extract doc comment contents.
Class Method Summary collapse
-
.purify(input) ⇒ Object
Extracts content inside /** …
Class Method Details
.purify(input) ⇒ Object
Extracts content inside /** … */
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jsduck/doc/comment.rb', line 8 def self.purify(input) result = [] # We can have two types of lines: # - those beginning with * # - and those without it indent = nil input.each_line do |line| line.chomp! if line =~ /\A\s*\*\s?(.*)\z/ # When comment contains *-lines, switch indent-trimming off indent = 0 result << $1 elsif line =~ /\A\s*\z/ # pass-through empty lines result << line elsif indent == nil && line =~ /\A(\s*)(.*?\z)/ # When indent not measured, measure it and remember indent = $1.length result << $2 else # Trim away indent if available result << line.sub(/\A\s{0,#{indent||0}}/, "") end end result.join("\n") end |