Class: PuppetStrings::Yard::Parsers::Puppet::Statement
- Inherits:
-
Object
- Object
- PuppetStrings::Yard::Parsers::Puppet::Statement
- Defined in:
- lib/puppet-strings/yard/parsers/puppet/statement.rb
Overview
Represents the base Puppet language statement.
Direct Known Subclasses
Constant Summary collapse
- COMMENT_REGEX =
The pattern for parsing docstring comments.
/^\s*#+\s?/.freeze
Instance Attribute Summary collapse
-
#comments_range ⇒ Object
readonly
Returns the value of attribute comments_range.
-
#docstring ⇒ Object
readonly
Returns the value of attribute docstring.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#comments ⇒ String
Gets the full comments of the statement.
-
#comments_hash_flag ⇒ Boolean
Determines if the comments have hash flag.
-
#extract_docstring(lines) ⇒ void
Extracts the docstring for the statement given the source lines.
-
#initialize(object, file) ⇒ Statement
constructor
Initializes the Puppet language statement.
-
#show ⇒ String
Shows the first line context for the statement.
Constructor Details
#initialize(object, file) ⇒ Statement
Initializes the Puppet language statement.
17 18 19 20 21 22 23 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 17 def initialize(object, file) @file = file @source = PuppetStrings::Yard::Util.ast_to_text(object) @line = object.line @comments_range = nil end |
Instance Attribute Details
#comments_range ⇒ Object (readonly)
Returns the value of attribute comments_range.
12 13 14 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12 def comments_range @comments_range end |
#docstring ⇒ Object (readonly)
Returns the value of attribute docstring.
12 13 14 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12 def docstring @docstring end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
12 13 14 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12 def line @line end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
12 13 14 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12 def source @source end |
Instance Method Details
#comments ⇒ String
Gets the full comments of the statement.
53 54 55 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 53 def comments @docstring.all end |
#comments_hash_flag ⇒ Boolean
Determines if the comments have hash flag.
59 60 61 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 59 def comments_hash_flag false end |
#extract_docstring(lines) ⇒ void
This method returns an undefined value.
Extracts the docstring for the statement given the source lines.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 28 def extract_docstring(lines) comment = [] (0..@line - 2).reverse_each do |index| break unless index <= lines.count line = lines[index].strip count = line.size line.gsub!(COMMENT_REGEX, '') # Break out if nothing was removed (wasn't a comment line) break unless line.size < count comment << line end @comments_range = (@line - comment.size - 1..@line - 1) @docstring = YARD::Docstring.new(comment.reverse.join("\n")) end |
#show ⇒ String
Shows the first line context for the statement.
47 48 49 |
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 47 def show "\t#{@line}: #{first_line}" end |