Class: Inch::Language::JavaScript::Provider::JSDoc::Docstring
Constant Summary
collapse
- VISIBILITIES =
%w(public protected private)
Instance Method Summary
collapse
#code_examples, #describes_private_object?, #empty?, #mentions_member?, #to_s
Constructor Details
#initialize(text) ⇒ Docstring
Returns a new instance of Docstring.
10
11
12
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 10
def initialize(text)
@text = (text)
end
|
Instance Method Details
#contains_code_example? ⇒ Boolean
14
15
16
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 14
def contains_code_example?
tag?(:example) || super
end
|
#describes_internal_api? ⇒ Boolean
18
19
20
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 18
def describes_internal_api?
tag?(:api, :private) || super
end
|
#describes_parameter?(name) ⇒ Boolean
22
23
24
25
26
27
28
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 22
def describes_parameter?(name)
return false if name.nil?
parameter = parameter_notations(name)
type_notation = /(\{[^\}]+\}|\[[^\]]+\])/ type_and_param = /(#{type_notation}\s+#{parameter}|#{parameter}\s+#{type_notation})/ tag?(:param, /#{type_and_param}\s+\S+/)
end
|
#describes_return? ⇒ Boolean
40
41
42
43
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 40
def describes_return?
type_notation = /(\{[^\}]+\}|\[[^\]]+\])/
tag?(:return, /#{type_notation}*(\s\w+)/) || super
end
|
#mentions_parameter?(name) ⇒ Boolean
30
31
32
33
34
|
# File 'lib/inch/language/javascript/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
36
37
38
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 36
def mentions_return?
tag?(:return) || super
end
|
#tag?(tagname, regex = nil) ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 53
def tag?(tagname, regex = nil)
tag_regex = /^\s*\@#{tagname}([^\n]*)$/m
matches = @text.scan(tag_regex).flatten
if !matches.empty?
if regex.nil?
true
else
matches.any? do |matched|
matched =~ /#{regex}/
end
end
end
end
|
#visibility(access_value = nil) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 46
def visibility(access_value = nil)
tagged_value = VISIBILITIES.detect do |v|
tag?(v)
end
(tagged_value || access_value || 'public').to_sym
end
|
Removes the comment markers // /* */ from the given text
.
Docstring.new("// test").
73
74
75
76
77
|
# File 'lib/inch/language/javascript/provider/jsdoc/docstring.rb', line 73
def (text)
text.to_s.lines.map do |line|
line.strip.gsub(/^(\s*(\/\*+|\/\/|\*+\/|\*)+\s?)/m, '')
end.join("\n").strip
end
|