Module: YARD::Markdown::MethodPresentationHelper

Defined in:
lib/yard/markdown/method_presentation_helper.rb

Overview

Formats method and attribute names for Markdown headings.

Instance Method Summary collapse

Instance Method Details

#attribute_access(attribute) ⇒ String

Returns the access marker for an attribute.

Parameters:

  • attribute (YARD::CodeObjects::MethodObject)

    Attribute reader or writer.

Returns:

  • (String)

    Access mode marker such as ‘R`, `W`, or `RW`.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yard/markdown/method_presentation_helper.rb', line 36

def attribute_access(attribute)
  info = attribute.attr_info || {}
  return 'RW' if info[:read] && info[:write]
  return 'R' if info[:read]
  return 'W' if info[:write]

  return 'RW' if attribute.reader? && attribute.writer?
  return 'R' if attribute.reader?

  'W'
end

#formatted_method_heading(method_object) ⇒ String

Builds the display heading for a method.

Parameters:

  • method_object (YARD::CodeObjects::MethodObject)

    Method being rendered.

Returns:

  • (String)

    Method heading text.



11
12
13
14
15
16
# File 'lib/yard/markdown/method_presentation_helper.rb', line 11

def formatted_method_heading(method_object)
  name = method_object.name
  signature = method_signature(method_object)
  signature = " #{signature}" if name.end_with?(']')
  "#{name}#{signature}"
end

#method_signature(method_object) ⇒ String

Returns the rendered parameter list for a method.

Parameters:

  • method_object (YARD::CodeObjects::MethodObject)

    Method being rendered.

Returns:

  • (String)

    Parenthesized method signature.



22
23
24
25
26
27
28
29
30
# File 'lib/yard/markdown/method_presentation_helper.rb', line 22

def method_signature(method_object)
  return '()' if method_object.parameters.nil?

  rendered = method_object.parameters.map do |name, default|
    default.nil? || default.empty? ? name : "#{name} = #{default}"
  end

  "(#{rendered.join(', ')})"
end