Class: Bake::Documentation
- Inherits:
-
Object
- Object
- Bake::Documentation
- Defined in:
- lib/bake/documentation.rb
Overview
Structured access to a set of comment lines.
Constant Summary collapse
- DESCRIPTION =
/\A\s*([^@\s].*)?\z/
- ATTRIBUTE =
/\A\s*@(?<name>.*?)\s+(?<value>.*?)\z/
- PARAMETER =
/\A@param(eter)?\s+(?<name>.*?)\s+\[(?<type>.*?)\](\s+(?<details>.*?))?\z/
Instance Method Summary collapse
-
#attributes ⇒ Object
The attribute lines of the comment block.
-
#description ⇒ Object
The text-only lines of the comment block.
-
#initialize(comments) ⇒ Documentation
constructor
Initialize the documentation with an array of comments.
-
#parameters ⇒ Object
The parameter lines of the comment block.
Constructor Details
#initialize(comments) ⇒ Documentation
Initialize the documentation with an array of comments.
14 15 16 |
# File 'lib/bake/documentation.rb', line 14 def initialize(comments) @comments = comments end |
Instance Method Details
#attributes ⇒ Object
The attribute lines of the comment block. e.g. ‘@returns [String]`.
57 58 59 60 61 62 63 64 65 |
# File 'lib/bake/documentation.rb', line 57 def attributes return to_enum(:attributes) unless block_given? @comments.each do |comment| if match = comment.match(ATTRIBUTE) yield match end end end |
#description ⇒ Object
The text-only lines of the comment block.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bake/documentation.rb', line 25 def description return to_enum(:description) unless block_given? # We track empty lines and only yield a single empty line when there is another line of text: gap = false @comments.each do |comment| if match = comment.match(DESCRIPTION) if match[1] if gap yield "" gap = false end yield match[1] else gap = true end else break end end end |
#parameters ⇒ Object
The parameter lines of the comment block. e.g. ‘@parameter value [String] The value.`
75 76 77 78 79 80 81 82 83 |
# File 'lib/bake/documentation.rb', line 75 def parameters return to_enum(:parameters) unless block_given? @comments.each do |comment| if match = comment.match(PARAMETER) yield match end end end |