class YARD::Docstring

itself is responsible for parsing the inner tags.
Tags can be nested in a documentation string, though the {Tags::Tag}
# @version 1.0
# a.reverse
# a = “hello world”
# @example My example
can be indented:
long as they are indented. The following +@example+ tag shows how tags
in the form +@tag VALUE+, where VALUE can span over multiple lines as
comments and metadata, or “tags”, of an object. Meta-data is expressed
A documentation string, or “docstring” for short, encapsulates the

def self.new!(text, tags = [], object = nil, raw_data = nil, ref_object = nil)

Parameters:
  • ref_object (CodeObjects::Base, nil) -- a reference object used for
  • raw_data (String) -- the complete docstring, including all
  • object (CodeObjects::Base, nil) -- the object associated with the
  • tags (Array) -- the list of tag objects in the docstring
  • text (String) -- the textual portion of the docstring
def self.new!(text, tags = [], object = nil, raw_data = nil, ref_object = nil)
  docstring = allocate
  docstring.replace(text, false)
  docstring.object = object
  docstring.add_tag(*tags)
  docstring.instance_variable_set("@unresolved_reference", ref_object)
  docstring.instance_variable_set("@all", raw_data) if raw_data
  docstring
end

def +(other)

Returns:
  • (Docstring) - a new docstring with both docstrings combines

Parameters:
  • other (Docstring, String) -- the other docstring (or string) to
def +(other)
  case other
  when Docstring
    Docstring.new([all, other.all].join("\n"), object)
  else
    super
  end
end

def add_tag(*tags)

Returns:
  • (void) -

Parameters:
  • tags (Tags::Tag, Tags::RefTag) -- list of tag objects to add
def add_tag(*tags)
  tags.each_with_index do |tag, i|
    case tag
    when Tags::Tag
      tag.object = object
      @tags << tag
    when Tags::RefTag, Tags::RefTagList
      @ref_tags << tag
    else
      raise ArgumentError, "expected Tag or RefTag, got #{tag.class} (at index #{i})"
    end
  end
end

def blank?(only_visible_tags = true)

Returns:
  • (Boolean) - whether or not the docstring has content

Parameters:
  • only_visible_tags (Boolean) -- whether only {Tags::Library.visible_tags}
def blank?(only_visible_tags = true)
  if only_visible_tags
    empty? && !tags.any? {|tag| Tags::Library.visible_tags.include?(tag.tag_name.to_sym) }
  else
    empty? && @tags.empty? && @ref_tags.empty?
  end
end

def convert_ref_tags

Returns:
  • (Array) - the list of valid reference tags
def convert_ref_tags
  list = @ref_tags.reject {|t| CodeObjects::Proxy === t.owner }
  @ref_tag_recurse_count ||= 0
  @ref_tag_recurse_count += 1
  if @ref_tag_recurse_count > 2
    log.error "#{@object.file}:#{@object.line}: Detected circular reference tag in " \
              "`#{@object}', ignoring all reference tags for this object " \
              "(#{@ref_tags.map {|t| "@#{t.tag_name}" }.join(", ")})."
    @ref_tags = []
    return @ref_tags
  end
  list = list.map(&:tags).flatten
  @ref_tag_recurse_count -= 1
  list
end

def delete_tag_if(&block)

Other tags:
    Since: - 0.7.0

Returns:
  • (void) -

Other tags:
    Yieldreturn: - true if the tag should be deleted

Other tags:
    Yieldparam: tag - the tag that is being tested
def delete_tag_if(&block)
  @tags.delete_if(&block)
  @ref_tags.delete_if(&block)
end

def delete_tags(name)

Other tags:
    Since: - 0.7.0

Returns:
  • (void) -

Parameters:
  • name (String) -- the tag name
def delete_tags(name)
  delete_tag_if {|tag| tag.tag_name.to_s == name.to_s }
end

def dup

Other tags:
    Since: - 0.7.0

Returns:
  • (Docstring) - a new copied docstring

Other tags:
    Note: - This method creates a new docstring with new tag lists, but does
def dup
  resolve_reference
  obj = super
  %w(all summary tags ref_tags).each do |name|
    val = instance_variable_defined?("@#{name}") && instance_variable_get("@#{name}")
    obj.instance_variable_set("@#{name}", val ? val.dup : nil)
  end
  obj
end

def has_tag?(name)

Returns:
  • (Boolean) - whether or not the tag +name+ was declared

Parameters:
  • name (String) -- the tag name to search for
def has_tag?(name)
  tags.any? {|tag| tag.tag_name.to_s == name.to_s }
end

def hash_flag=(v) @hash_flag = v.nil? ? false : v end

def hash_flag=(v) @hash_flag = v.nil? ? false : v end

def initialize(content = '', object = nil)

Parameters:
  • object (CodeObjects::Base) -- an object to associate the docstring
  • content (String) -- the raw comments to be parsed into a docstring

Other tags:
    Note: - To properly parse directives with proper parser context within
def initialize(content = '', object = nil)
  @object = object
  @summary = nil
  @hash_flag = false
  self.all = content
end

def line

Returns:
  • (nil) - if there is no associated {#line_range}
  • (Fixnum) - the first line of the {#line_range}
def line
  line_range ? line_range.first : nil
end

def parse_comments(comments)

Returns:
  • (String) - the non-metadata portion of the comments to

Parameters:
  • comments (String) --
def parse_comments(comments)
  parser = self.class.parser
  parser.parse(comments, object)
  @all = parser.raw_text
  @unresolved_reference = parser.reference
  add_tag(*parser.tags)
  parser.text
end

def parser(*args) default_parser.new(*args) end

Returns:
  • (DocstringParser) - the parser object used to parse a

Parameters:
  • args () -- arguments are passed to the {DocstringParser}
def parser(*args) default_parser.new(*args) end

def replace(content, parse = true)

Parameters:
  • content (String) -- the raw comments to be parsed
def replace(content, parse = true)
  content = content.join("\n") if content.is_a?(Array)
  @tags = []
  @ref_tags = []
  if parse
    super(parse_comments(content))
  else
    @all = content
    @unresolved_reference = nil
    super(content)
  end
end

def resolve_reference

Returns:
  • (void) -
def resolve_reference
  loop do
    return if defined?(@unresolved_reference).nil? || @unresolved_reference.nil?
    return if CodeObjects::Proxy === @unresolved_reference
    reference = @unresolved_reference
    @unresolved_reference = nil
    self.all = [reference.docstring.all, @all].join("\n")
  end
end

def stable_sort_by(list)

Returns:
  • (Array) - a stable sorted list.

Parameters:
  • list (Enumerable) -- the list to sort.
def stable_sort_by(list)
  list.each_with_index.sort_by {|tag, i| [yield(tag), i] }.map(&:first)
end

def summary

Returns:
  • (String) - The first line or paragraph of the docstring; always ends with a period.
def summary
  resolve_reference
  return @summary if defined?(@summary) && @summary
  stripped = gsub(/[\r\n](?![\r\n])/, ' ').strip
  num_parens = 0
  idx = length.times do |index|
    case stripped[index, 1]
    when "."
      next_char = stripped[index + 1, 1].to_s
      break index - 1 if num_parens <= 0 && next_char =~ /^\s*$/
    when "\r", "\n"
      next_char = stripped[index + 1, 1].to_s
      if next_char =~ /^\s*$/
        break stripped[index - 1, 1] == '.' ? index - 2 : index - 1
      end
    when "{", "(", "["
      num_parens += 1
    when "}", ")", "]"
      num_parens -= 1
    end
  end
  @summary = stripped[0..idx]
  if !@summary.empty? && @summary !~ /\A\s*\{include:.+\}\s*\Z/
    @summary += '.'
  end
  @summary
end

def tag(name)

Returns:
  • (Tags::Tag) - the first tag in the list of {#tags}

Parameters:
  • name (#to_s) -- the tag name to return data for
def tag(name)
  tags.find {|tag| tag.tag_name.to_s == name.to_s }
end

def tags(name = nil)

Returns:
  • (Array) - the list of tags by the specified tag name

Parameters:
  • name (#to_s) -- the tag name to return data for, or nil for all tags
def tags(name = nil)
  list = stable_sort_by(@tags + convert_ref_tags, &:tag_name)
  return list unless name
  list.select {|tag| tag.tag_name.to_s == name.to_s }
end

def to_raw

Other tags:
    Todo: - Add Tags::Tag#to_raw and refactor

Other tags:
    Since: - 0.7.0

Returns:
  • (String) - the updated raw formatted docstring data
def to_raw
  tag_data = tags.map do |tag|
    case tag
    when Tags::OverloadTag
      tag_text = "@#{tag.tag_name} #{tag.signature}\n"
      unless tag.docstring.blank?
        tag_text += "\n  " + tag.docstring.all.gsub(/\r?\n/, "\n  ")
      end
    when Tags::OptionTag
      tag_text = "@#{tag.tag_name} #{tag.name}"
      tag_text += ' [' + tag.pair.types.join(', ') + ']' if tag.pair.types
      tag_text += ' ' + tag.pair.name.to_s if tag.pair.name
      tag_text += "\n " if tag.name && tag.text
      tag_text += ' (' + tag.pair.defaults.join(', ') + ')' if tag.pair.defaults
      tag_text += " " + tag.pair.text.strip.gsub(/\n/, "\n  ") if tag.pair.text
    else
      tag_text = '@' + tag.tag_name
      tag_text += ' [' + tag.types.join(', ') + ']' if tag.types
      tag_text += ' ' + tag.name.to_s if tag.name
      tag_text += "\n " if tag.name && tag.text
      tag_text += ' ' + tag.text.strip.gsub(/\n/, "\n  ") if tag.text
    end
    tag_text
  end
  [strip, tag_data.join("\n")].reject(&:empty?).compact.join("\n")
end

def to_s

def to_s
  resolve_reference
  super
end