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 +(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)

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
      @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 }
  list.map {|t| t.tags }.flatten
end

def create_ref_tag(tag_name, name, object_name)

Creates a {Tags::RefTag}
def create_ref_tag(tag_name, name, object_name)
  @ref_tags << Tags::RefTagList.new(tag_name, P(object, object_name), name)
end

def create_tag(tag_name, tag_buf)

Returns:
  • (Tags::Tag, Tags::RefTag) - a tag

Parameters:
  • tag_buf (String) -- the text attached to the tag with newlines removed.
  • tag_name (String) -- the tag name
def create_tag(tag_name, tag_buf)
  if tag_buf =~ /\A\s*(?:(\S+)\s+)?\(\s*see\s+(\S+)\s*\)\s*\Z/
    return create_ref_tag(tag_name, $1, $2)
  end
    
  tag_factory = Tags::Library.instance
  tag_method = "#{tag_name}_tag"
  if tag_name && tag_factory.respond_to?(tag_method)
    add_tag(*[tag_factory.send(tag_method, tag_buf)].flatten)
  else
    log.warn "Unknown tag @#{tag_name}" + (object ? " in file `#{object.file}` near line #{object.line}" : "")
  end
rescue Tags::TagFormatError
  log.warn "Invalid tag format for @#{tag_name}" + (object ? " in file `#{object.file}` near line #{object.line}" : "")
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
def initialize(content = '', object = nil)
  @object = object
  @summary = nil
  @hash_flag = false
  
  self.all = content
end

def line

Returns:
  • (Fixnum) - the first line of the {#line_range}.
def line
  line_range.first
end

def parse_comments(comments)

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

Parameters:
  • comments (String) --
def parse_comments(comments)
  comments = comments.split(/\r?\n/) if comments.is_a?(String)
  return '' if !comments || comments.empty?
  docstring = ""
  indent, last_indent = comments.first[/^\s*/].length, 0
  orig_indent = 0
  last_line = ""
  tag_name, tag_klass, tag_buf = nil, nil, []
  (comments+['']).each_with_index do |line, index|
    indent = line[/^\s*/].length 
    empty = (line =~ /^\s*$/ ? true : false)
    done = comments.size == index
    if tag_name && (((indent < orig_indent && !empty) || done || 
        (indent == 0 && !empty)) || (indent <= last_indent && line =~ META_MATCH))
      create_tag(tag_name, tag_buf.join("\n"))
      tag_name, tag_buf, = nil, []
      orig_indent = 0
    end
    # Found a meta tag
    if line =~ META_MATCH
      tag_name, tag_buf = $1, [($2 || '')]
    elsif tag_name && indent >= orig_indent && !empty
      orig_indent = indent if orig_indent == 0
      # Extra data added to the tag on the next line
      last_empty = last_line =~ /^[ \t]*$/ ? true : false
      
      tag_buf << '' if last_empty
      tag_buf << line.gsub(/^[ \t]{#{orig_indent}}/, '')
    elsif !tag_name
      # Regular docstring text
      docstring << line << "\n" 
    end
    last_indent = indent
    last_line = line
  end
  # Remove trailing/leading whitespace / newlines
  docstring.gsub!(/\A[\r\n\s]+|[\r\n\s]+\Z/, '')
end

def replace(content)

Parameters:
  • content (String) -- the raw comments to be parsed
def replace(content)
  @tags, @ref_tags = [], []
  @all = content
  super parse_comments(content)
end

def summary

Returns:
  • (String) - The first line or paragraph of the docstring; always ends with a period.
def summary
  return @summary if @summary
  open_parens = ['{', '(', '[']
  close_parens = ['}', ')', ']']
  num_parens = 0
  idx = length.times do |index|
    case self[index, 1]
    when ".", "\r", "\n"
      next_char = self[index + 1, 1].to_s
      if num_parens == 0 && next_char =~ /^\s*$/
        break index - 1
      end
    when "{", "(", "["
      num_parens += 1
    when "}", ")", "]"
      num_parens -= 1
    end
  end
  @summary = self[0..idx]
  @summary += '.' unless @summary.empty?
  @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 = @tags + convert_ref_tags
  return list unless name
  list.select {|tag| tag.tag_name.to_s == name.to_s }
end