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.



44
45
46
47
48
49
# File 'lib/yard/tags/tag.rb', line 44

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



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

def name
  @name
end

#objectCodeObjects::Base



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

def object
  @object
end

#tag_nameString



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

def tag_name
  @tag_name
end

#textString?



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

def text
  @text
end

#typesArray<String>?



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

def types
  @types
end

Instance Method Details

#explain_typesString?

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



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

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.

See Also:



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

def type
  types.first
end