Class: Asciidoctor::DocTest::Example
- Inherits:
-
Object
- Object
- Asciidoctor::DocTest::Example
- Defined in:
- lib/asciidoctor/doctest/example.rb
Overview
This class represents a single test example.
Constant Summary collapse
- NAME_SEPARATOR =
':'
Instance Attribute Summary collapse
-
#content ⇒ String
Raw content.
-
#desc ⇒ String
Description.
-
#group_name ⇒ String
The first part of the name.
-
#local_name ⇒ String
The second part of the name.
-
#opts ⇒ Hash
Options.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
true
ifself
andother
equals in attributesgroup_name
,local_name
andcontent
(compared using ==), otherwisefalse
. -
#[](name) ⇒ Array<String>, Boolean
Returns value(s) of the named option.
-
#[]=(name, value) ⇒ Object
Sets or unsets the option.
-
#empty? ⇒ Boolean
true
when the content is blank,false
otherwise. -
#eql?(other) ⇒ Boolean
true
ifself
andother
are instances of the same class and all their attributes are equal (compared using ==), otherwisefalse
. -
#hash ⇒ Object
:nocov:.
-
#initialize(name, content: '', desc: '', opts: {}) ⇒ Example
constructor
A new instance of Example.
-
#name ⇒ String
The name in format
group_name:local_name
. - #name=(*name) ⇒ Object
-
#name_match?(pattern) ⇒ Boolean
true
if the name matches against thepattern
,false
otherwise. -
#to_s ⇒ String
A copy of the content.
Constructor Details
#initialize(name, content: '', desc: '', opts: {}) ⇒ Example
Returns a new instance of Example.
35 36 37 38 39 40 |
# File 'lib/asciidoctor/doctest/example.rb', line 35 def initialize(name, content: '', desc: '', opts: {}) self.name = name @content = content @desc = desc @opts = opts end |
Instance Attribute Details
#content ⇒ String
Returns raw content.
21 22 23 |
# File 'lib/asciidoctor/doctest/example.rb', line 21 def content @content end |
#desc ⇒ String
Returns description.
24 25 26 |
# File 'lib/asciidoctor/doctest/example.rb', line 24 def desc @desc end |
#group_name ⇒ String
Returns the first part of the name.
15 16 17 |
# File 'lib/asciidoctor/doctest/example.rb', line 15 def group_name @group_name end |
#local_name ⇒ String
Returns the second part of the name.
18 19 20 |
# File 'lib/asciidoctor/doctest/example.rb', line 18 def local_name @local_name end |
#opts ⇒ Hash
Returns options.
27 28 29 |
# File 'lib/asciidoctor/doctest/example.rb', line 27 def opts @opts end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true
if self
and other
equals in attributes group_name
, local_name
and content
(compared using ==), otherwise false
.
115 116 117 118 119 120 |
# File 'lib/asciidoctor/doctest/example.rb', line 115 def ==(other) [:group_name, :local_name, :content].all? do |name| other.respond_to?(name) && public_send(name) == other.public_send(name) end end |
#[](name) ⇒ Array<String>, Boolean
Returns value(s) of the named option.
74 75 76 |
# File 'lib/asciidoctor/doctest/example.rb', line 74 def [](name) @opts[name.to_sym] end |
#[]=(name, value) ⇒ Object
Sets or unsets the option.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/asciidoctor/doctest/example.rb', line 87 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 |
#empty? ⇒ Boolean
Returns true
when the content is blank, false
otherwise.
100 101 102 |
# File 'lib/asciidoctor/doctest/example.rb', line 100 def empty? content.blank? end |
#eql?(other) ⇒ Boolean
Returns true
if self
and other
are instances of the same class and all their attributes are equal (compared using ==), otherwise false
.
127 128 129 130 |
# File 'lib/asciidoctor/doctest/example.rb', line 127 def eql?(other) self.class == other.class && instance_values == other.instance_values end |
#hash ⇒ Object
:nocov:
133 134 135 |
# File 'lib/asciidoctor/doctest/example.rb', line 133 def hash self.class.hash ^ instance_values.hash end |
#name ⇒ String
Returns the name in format group_name:local_name
.
44 45 46 |
# File 'lib/asciidoctor/doctest/example.rb', line 44 def name [@group_name, @local_name].join(NAME_SEPARATOR) end |
#name=(*name) ⇒ Object
52 53 54 55 |
# File 'lib/asciidoctor/doctest/example.rb', line 52 def name=(*name) name.flatten! @group_name, @local_name = name.one? ? name.first.split(NAME_SEPARATOR, 2) : name end |
#name_match?(pattern) ⇒ Boolean
Returns true
if the name matches against the pattern
, false
otherwise.
61 62 63 64 65 66 |
# File 'lib/asciidoctor/doctest/example.rb', line 61 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 ⇒ String
Returns a copy of the content.
106 107 108 |
# File 'lib/asciidoctor/doctest/example.rb', line 106 def to_s content.dup end |