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

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

Constant Summary collapse

VISIBILITIES =
%w(public protected private)

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)

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

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

#describes_parameter?(name) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#describes_return?Boolean

Returns:

  • (Boolean)

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

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

#mentions_parameter?(name) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#mentions_return?Boolean

Returns:

  • (Boolean)

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

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

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

Returns:

  • (Boolean)

54
55
56
57
58
59
60
61
62
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 54

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

#visibilityObject


47
48
49
50
51
52
# File 'lib/inch/language/nodejs/provider/jsdoc/docstring.rb', line 47

def visibility
  tagged_value = VISIBILITIES.detect do |v|
    tag?(v)
  end
  (tagged_value || 'public').to_sym
end

#without_comment_markersString

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

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

Returns:

  • (String)

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

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