Class: DuckTesting::YARD::MethodParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_testing/yard/method_parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_object, name, default, parameter_tag) ⇒ MethodParameter

Returns a new instance of MethodParameter.

Parameters:



10
11
12
13
14
15
# File 'lib/duck_testing/yard/method_parameter.rb', line 10

def initialize(method_object, name, default, parameter_tag)
  @method_object = method_object
  @name = name
  @default = default
  @parameter_tag = parameter_tag
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



4
5
6
# File 'lib/duck_testing/yard/method_parameter.rb', line 4

def default
  @default
end

#method_objectObject (readonly)

Returns the value of attribute method_object.



4
5
6
# File 'lib/duck_testing/yard/method_parameter.rb', line 4

def method_object
  @method_object
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/duck_testing/yard/method_parameter.rb', line 4

def name
  @name
end

#parameter_tagObject (readonly)

Returns the value of attribute parameter_tag.



4
5
6
# File 'lib/duck_testing/yard/method_parameter.rb', line 4

def parameter_tag
  @parameter_tag
end

Instance Method Details

#documented?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/duck_testing/yard/method_parameter.rb', line 29

def documented?
  !parameter_tag.nil?
end

#expected_typesArray<DuckTesting::Type::Base>

Returns:



44
45
46
# File 'lib/duck_testing/yard/method_parameter.rb', line 44

def expected_types
  parameter_tag ? DuckTesting::YARD.expected_types(parameter_tag.types) : []
end

#key_nameSymbol?

Returns:

  • (Symbol, nil)


39
40
41
# File 'lib/duck_testing/yard/method_parameter.rb', line 39

def key_name
  keyword? ? name[0...-1].to_sym : nil
end

#keyword?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/duck_testing/yard/method_parameter.rb', line 34

def keyword?
  name.end_with?(":")
end

#to_sString

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
# File 'lib/duck_testing/yard/method_parameter.rb', line 18

def to_s
  if default.nil?
    name
  elsif name.end_with?(":")
    "#{name} #{default}"
  else
    "#{name} = #{default}"
  end
end