class Asciidoctor::DocTest::BaseExample

This class represents a single test example.

Constants

NAME_SEPARATOR

Attributes

content[RW]

@return [String] raw content.

desc[RW]

@return [String] description.

group_name[RW]

@return [String] the first part of the name.

local_name[RW]

@return [String] the second part of the name.

opts[RW]

@return [Hash] options.

Public Class Methods

new(name, content: '', desc: '', opts: {}) click to toggle source

@param name (see name=) @param content [String] @param desc [String] description @param opts [Hash] options

# File lib/asciidoctor/doctest/base_example.rb, line 34
def initialize(name, content: '', desc: '', opts: {})
  self.name = name
  @content = content
  @desc = desc
  @opts = opts
end

Public Instance Methods

==(other) click to toggle source

@param other the object to compare with. @return [Boolean] true if self and other equals in attributes

+group_name+, +local_name+ and +content_normalized+ (compared
using +==+), otherwise +false+.
# File lib/asciidoctor/doctest/base_example.rb, line 135
def ==(other)
  [:group_name, :local_name, :content_normalized].all? do |name|
    other.respond_to?(name) &&
      public_send(name) == other.public_send(name)
  end
end
[](name) click to toggle source

Returns value(s) of the named option.

@param name [#to_sym] the option name. @return [Array<String>, Boolean] the option value.

# File lib/asciidoctor/doctest/base_example.rb, line 73
def [](name)
  @opts[name.to_sym]
end
[]=(name, value) click to toggle source

Sets or unsets the option.

@param name [#to_sym] the option name. @param value [Array<String>, Boolean, String, nil] the option value;

+Array+ and +Boolean+ are just assigned to the option, +nil+
removes the option and others are added to the option as an
array item.
# File lib/asciidoctor/doctest/base_example.rb, line 86
def []=(name, value)
  case value
  when nil
    @opts.delete(name.to_sym)
  when Array, TrueClass, FalseClass
    @opts[name.to_sym] = value.deep_dup
  else
    (@opts[name.to_sym] ||= []) << value.dup
  end
end
content_normalized() click to toggle source

@note The default implementation returns content as-is; subclasses

should override this method.

@return [String] copy of the content in a form that is suitable for

semantic comparison with another content.
# File lib/asciidoctor/doctest/base_example.rb, line 110
def content_normalized
  content.dup
end
content_pretty() click to toggle source

@note (see content_normalized)

@return [String] copy of the content in a human-readable (formatted)

shape for pretty print.
# File lib/asciidoctor/doctest/base_example.rb, line 120
def content_pretty
  content.dup
end
empty?() click to toggle source

@return [Boolean] true when the content is blank, false otherwise.

# File lib/asciidoctor/doctest/base_example.rb, line 99
def empty?
  content.blank?
end
eql?(other) click to toggle source

@param other [Object] the object to compare with. @return [Boolean] true if self and other are instances of the same

class and all their attributes are equal (compared using +==+),
otherwise +false+.
# File lib/asciidoctor/doctest/base_example.rb, line 147
def eql?(other)
  self.class == other.class &&
    instance_values == other.instance_values
end
hash() click to toggle source

:nocov:

# File lib/asciidoctor/doctest/base_example.rb, line 153
def hash
  self.class.hash ^ instance_values.hash
end
name() click to toggle source

@return [String] the name in format group_name:local_name.

# File lib/asciidoctor/doctest/base_example.rb, line 43
def name
  [@group_name, @local_name].join(NAME_SEPARATOR)
end
name=(*name) click to toggle source

@param name [String, Array<String>] a String in format

+group_name:local_name+, or an Array with the group_name and the
local_name.
# File lib/asciidoctor/doctest/base_example.rb, line 51
def name=(*name)
  name.flatten!
  @group_name, @local_name = name.one? ? name.first.split(NAME_SEPARATOR, 2) : name
end
name_match?(pattern) click to toggle source

@param pattern [String] the glob pattern (e.g. +block_:with+). @return [Boolean] true if the name matches against the pattern,

+false+ otherwise.
# File lib/asciidoctor/doctest/base_example.rb, line 60
def name_match?(pattern)
  globs = pattern.split(NAME_SEPARATOR, 2)
  [group_name, local_name].zip(globs).all? do |name, glob|
    File.fnmatch? glob || '*', name.to_s
  end
end
to_s() click to toggle source

@return (see content_pretty)

# File lib/asciidoctor/doctest/base_example.rb, line 126
def to_s
  content_pretty
end

Private Instance Methods

initialize_copy(source) click to toggle source

:nocov:

# File lib/asciidoctor/doctest/base_example.rb, line 160
def initialize_copy(source)
  instance_variables.each do |name|
    instance_variable_set name, instance_variable_get(name).deep_dup
  end
end