123456789_123456789_123456789_123456789_123456789_

Class: YARD::Tags::Tag

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/yard/tags/tag.rb

Overview

Represents a metadata tag value (+@tag+). ::YARD::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')

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(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

[ GitHub ]

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

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

Instance Attribute Details

#nameString? (rw)

Returns:

  • (String)

    a name associated with the tag

  • (nil)

    if no tag name is supplied

[ GitHub ]

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

attr_accessor :name

#objectCodeObjects::Base (rw)

Returns:

[ GitHub ]

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

attr_accessor :object

#tag_nameString (rw)

Returns:

  • (String)

    the name of the tag

[ GitHub ]

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

attr_accessor :tag_name

#textString? (rw)

Returns:

  • (String)

    the tag text associated with the tag

  • (nil)

    if no tag text is supplied

[ GitHub ]

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

attr_accessor :text

#typesArray<String>? (rw)

Returns:

  • (Array<String>)

    a list of types associated with the tag

  • (nil)

    if no types are associated with the tag

[ GitHub ]

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

attr_accessor :types

Instance Method Details

#explain_typesString?

Provides a plain English summary of the type specification, or nil if no types are provided or parsable.

Returns:

  • (String)

    a plain English description of the associated types

  • (nil)

    if no types are provided or not parsable

[ GitHub ]

  
# File 'lib/yard/tags/tag.rb', line 66

def explain_types
  return nil if !types || types.empty?
  TypesExplainer.explain(*types)
end

#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:

[ GitHub ]

  
# File 'lib/yard/tags/tag.rb', line 57

def type
  types.first
end