Class: PuppetStrings::Yard::Parsers::Puppet::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-strings/yard/parsers/puppet/statement.rb

Overview

Represents the base Puppet language statement.

Constant Summary collapse

COMMENT_REGEX =

The pattern for parsing docstring comments.

/^\s*#+\s?/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, file) ⇒ Statement

Initializes the Puppet language statement.

Parameters:

  • object

    The Puppet parser model object for the statement.

  • file (String)

    The file name of the file containing the 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_rangeObject (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

#docstringObject (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

#fileObject (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

#lineObject (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

#sourceObject (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

#commentsString

Gets the full comments of the statement.

Returns:

  • (String)

    Returns 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_flagBoolean

Determines if the comments have hash flag.

Returns:

  • (Boolean)

    Returns true if the comments have a hash flag or false if not.



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.

Parameters:

  • lines (Array<String>)

    The source lines for the file containing the statement.



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

#showString

Shows the first line context for the statement.

Returns:

  • (String)

    Returns 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