Class: YARD::Tags::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/tags/tag.rb

Overview

Represents a metadata tag value (+@tag+). Tags can have any combination of #types, #name and #text, or none of the above.

Examples:

Programmatic tag creation

# The following docstring syntax:
#   @param [String, nil] arg an argument
#
# is equivalent to:
Tag.new(:param, 'an argument', ['String', 'nil'], 'arg')

Direct Known Subclasses

DefaultTag, OptionTag, OverloadTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, types = nil, name = nil) ⇒ Tag

Creates a new tag object with a tag name and text. Optionally, formally declared types and a key name can be specified.

Types are mainly for meta tags that rely on type information, such as param, return, etc.

Key names are for tags that declare meta data for a specific key or name, such as param, raise, etc.

Parameters:

  • tag_name (#to_s)

    the tag name to create the tag for

  • text (String)

    the descriptive text for this tag

  • types (Array<String>) (defaults to: nil)

    optional type list of formally declared types for the tag

  • name (String) (defaults to: nil)

    optional key name which the tag refers to



43
44
45
# File 'lib/yard/tags/tag.rb', line 43

def initialize(tag_name, text, types = nil, name = nil)
  @tag_name, @text, @name, @types = tag_name.to_s, text, name, (types ? [types].flatten.compact : nil)
end

Instance Attribute Details

#nameString

Returns a name associated with the tag.

Returns:

  • (String)

    a name associated with the tag



25
26
27
# File 'lib/yard/tags/tag.rb', line 25

def name
  @name
end

#objectCodeObjects::Base

Returns the associated object.

Returns:



28
29
30
# File 'lib/yard/tags/tag.rb', line 28

def object
  @object
end

#tag_nameString

Returns the name of the tag.

Returns:

  • (String)

    the name of the tag



14
15
16
# File 'lib/yard/tags/tag.rb', line 14

def tag_name
  @tag_name
end

#textString?

Returns:

  • (String)

    the tag text associated with the tag

  • (nil)

    if no tag text is supplied



18
19
20
# File 'lib/yard/tags/tag.rb', line 18

def text
  @text
end

#typesArray<String>?

Returns:

  • (Array<String>)

    a list of types associated with the tag

  • (nil)

    if no types are associated with the tag



22
23
24
# File 'lib/yard/tags/tag.rb', line 22

def types
  @types
end

Instance Method Details

#typeString

Convenience method to access the first type specified. This should mainly be used for tags that only specify one type.

Returns:

  • (String)

    the first of the list of specified types

See Also:



52
53
54
# File 'lib/yard/tags/tag.rb', line 52

def type
  types.first
end