class Asciidoctor::DocTest::BaseExample
This class represents a single test example.
Constants
- NAME_SEPARATOR
Attributes
@return [String] raw content.
@return [String] description.
@return [String] the first part of the name.
@return [String] the second part of the name.
@return [Hash] options.
Public Class Methods
@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
@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
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
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
@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
@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
@return [Boolean] true
when the content is blank, false
otherwise.
# File lib/asciidoctor/doctest/base_example.rb, line 99 def empty? content.blank? end
@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
:nocov:
# File lib/asciidoctor/doctest/base_example.rb, line 153 def hash self.class.hash ^ instance_values.hash end
@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
@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
@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
@return (see content_pretty
)
# File lib/asciidoctor/doctest/base_example.rb, line 126 def to_s content_pretty end
Private Instance Methods
: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