Class: Inch::Language::Ruby::Provider::YARD::Docstring

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/language/ruby/provider/yard/docstring.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Docstring

Returns a new instance of Docstring.



7
8
9
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 7

def initialize(text)
  @text = text.to_s
end

Instance Method Details

#code_examplesObject



27
28
29
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 27

def code_examples
  @code_examples ||= parse_code_examples
end

#contains_code_example?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 23

def contains_code_example?
  !code_examples.empty?
end

#describes_internal_api?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 11

def describes_internal_api?
  first_line =~ /^Internal\:\ .+/
end

#describes_parameter?(name) ⇒ Boolean

Returns true if the docstring describes the parameter with the given name.

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 33

def describes_parameter?(name)
  return false if name.nil?
  describe_parameter_regexps(name).any? do |pattern|
    @text.index(pattern)
  end
end

#describes_private_object?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 15

def describes_private_object?
  first_line =~ /^Private\:\ .+/
end

#describes_return?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 61

def describes_return?
  last_lines.any? do |line|
    line =~ /^#{tomdoc_modifiers}(Returns|Gets|Sets|Gets\/Sets)\ (\w+\s){2,}/i ||
      line =~ /^#{tomdoc_modifiers}(Returns|Gets|Sets|Gets\/Sets)\ (nil|nothing)\.*/i
  end
end

#empty?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 19

def empty?
  @text.strip.empty?
end

#mentions_member?(name) ⇒ Boolean

Returns true if the docstring mentions a member with the given name.

Returns:

  • (Boolean)


42
43
44
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 42

def mentions_member?(name)
  mentions_parameter?(name)
end

#mentions_parameter?(name) ⇒ Boolean

Returns true if the docstring mentions a parameter with the given name.

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 48

def mentions_parameter?(name)
  return false if name.nil?
  mention_parameter_regexps(name).any? do |pattern|
    @text.index(pattern)
  end
end

#mentions_return?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 55

def mentions_return?
  last_lines.any? do |line|
    line =~ /^#{tomdoc_modifiers}(Returns|Gets|Sets|Gets\/Sets)\ /
  end
end

#to_sObject



68
69
70
# File 'lib/inch/language/ruby/provider/yard/docstring.rb', line 68

def to_s
  @text
end