class PuppetStrings::Yard::Parsers::Puppet::Statement
Represents the base Puppet
language statement.
Constants
- COMMENT_REGEX
The pattern for parsing docstring comments.
Attributes
Public Class Methods
Initializes the Puppet
language statement. @param object The Puppet
parser model object for the statement. @param [String] file The file name of the file containing the statement.
# 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
Public Instance Methods
Gets the full comments of the statement. @return [String] Returns the full comments of the statement.
# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 53 def comments @docstring.all end
Determines if the comments have hash flag. @return [Boolean] Returns true if the comments have a hash flag or false if not.
# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 59 def comments_hash_flag false end
Extracts the docstring for the statement given the source lines. @param [Array<String>] lines The source lines for the file containing the statement. @return [void]
# 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
Shows the first line context for the statement. @return [String] Returns the first line context for the statement.
# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 47 def show "\t#{@line}: #{first_line}" end
Private Instance Methods
# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 65 def first_line @source.split(/\r?\n/).first.strip end