Class: Inch::Language::Ruby::Provider::YARD::Object::MethodParameterObject

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

Overview

Proxy class for method parameters

Constant Summary collapse

BAD_NAME_EXCEPTIONS =
%w(id)
BAD_NAME_THRESHOLD =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, name, in_signature, tag) ⇒ MethodParameterObject

Returns a new instance of MethodParameterObject.

Parameters:

  • method (YARD::Object::MethodObject)

    the method the parameter belongs to

  • name (String)

    the name of the parameter

  • in_signature (String)

    how the parameter is noted in the method’s signature

  • tag (YARD::Tags::Tag)

    the Tag object for the parameter



17
18
19
20
21
22
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 17

def initialize(method, name, in_signature, tag)
  @method = method
  @name = name
  @tag = tag
  @in_signature = in_signature
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 9

def name
  @name
end

Instance Method Details

#bad_name?Boolean

Returns true if the name of the parameter is uncommunicative.

Returns:

  • (Boolean)

    true if the name of the parameter is uncommunicative



29
30
31
32
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 29

def bad_name?
  return false if BAD_NAME_EXCEPTIONS.include?(name)
  name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
end

#block?Boolean

Returns true if the parameter is a block.

Returns:

  • (Boolean)

    true if the parameter is a block



35
36
37
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 35

def block?
  @in_signature.to_s =~ /^\&/
end

#described?Boolean

Returns true if an additional description given?.

Returns:

  • (Boolean)

    true if an additional description given?



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

def described?
  described_by_tag? || described_by_docstring?
end

#mentioned?Boolean

Returns true if the parameter is mentioned in the docs.

Returns:

  • (Boolean)

    true if the parameter is mentioned in the docs



46
47
48
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 46

def mentioned?
  !!@tag || mentioned_by_docstring?
end

#splat?Boolean

Returns true if the parameter is a splat argument.

Returns:

  • (Boolean)

    true if the parameter is a splat argument



51
52
53
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 51

def splat?
  @in_signature.to_s =~ /^\*/
end

#typed?Boolean

Returns true if the type of the parameter is defined.

Returns:

  • (Boolean)

    true if the type of the parameter is defined



56
57
58
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 56

def typed?
  @tag && @tag.types && !@tag.types.empty?
end

#wrongly_mentioned?Boolean

Returns true if the parameter is mentioned in the docs, but not present in the method’s signature.

Returns:

  • (Boolean)

    true if the parameter is mentioned in the docs, but not present in the method’s signature



62
63
64
# File 'lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb', line 62

def wrongly_mentioned?
  mentioned? && !@in_signature
end