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:

  • (Boolean)


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

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)


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

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)


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

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)


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

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)


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

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

#to_sObject



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

def to_s
  @text
end