Class: Inch::Language::Nodejs::Provider::JSDoc::Docstring

Inherits:
Ruby::Provider::YARD::Docstring show all
Defined in:
lib/inch/language/nodejs/provider/jsdoc/docstring.rb

Instance Method Summary collapse

Methods inherited from Ruby::Provider::YARD::Docstring

#code_examples, #contains_code_example?, #describes_private_object?, #empty?, #initialize, #to_s

Constructor Details

This class inherits a constructor from Inch::Language::Ruby::Provider::YARD::Docstring

Instance Method Details

#describes_internal_api?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 20

def describes_internal_api?
  tag?(:api, :private) || super
end

#describes_parameter?(name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 24

def describes_parameter?(name)
  return false if name.nil?
  parameter = parameter_notations(name)
  tag?(:param, /#{parameter}\s+\S+/)
end

#describes_return?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 40

def describes_return?
  type_notation = /(\{[^\}]+\}|\[[^\]]+\])/
  tag?(:return, /#{type_notation}*(\s\w+)/) || super
end

#mentions_parameter?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 30

def mentions_parameter?(name)
  return false if name.nil?
  parameter = parameter_notations(name)
  tag?(:param, /#{parameter}/) || super
end

#mentions_return?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 36

def mentions_return?
  tag?(:return) || super
end

#tag?(tagname, regex = nil) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 51

def tag?(tagname, regex = nil)
  if without_comment_markers =~ /^\s*\@#{tagname}([^\n]*)$/m
    if regex.nil?
      true
    else
      $1 =~ /#{regex}/
    end
  end
end

#visibilityObject



45
46
47
48
49
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 45

def visibility
  %w(public protected private).detect do |v|
    tag?(v)
  end || 'public'
end

#without_comment_markersString

Removes the comment markers // /* */ from the docstring.

Docstring.new("// test").without_comment_markers
# => "test"

Returns:

  • (String)


14
15
16
17
18
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 14

def without_comment_markers
  @text.lines.map do |line|
    line.strip.gsub(/^(\s*(\/\*+|\/\/|\*+\/|\*)+\s?)/m, '')
  end.join("\n").strip
end