Class: Documentrix::Utils::Tags
- Inherits:
-
Object
- Object
- Documentrix::Utils::Tags
- Includes:
- Enumerable
- Defined in:
- lib/documentrix/utils/tags.rb
Defined Under Namespace
Classes: Tag
Instance Method Summary collapse
- #add(tag, source: nil) ⇒ Object
-
#clear ⇒ Documentrix::Utils::Tags
The clear method resets the Documentrix::Utils::Tags instance's set by calling its clear method.
-
#each {|element| ... } ⇒ Documentrix::Utils::Tags
The each method iterates over this Tags instance's set and yields each tags to the given block.
-
#empty? ⇒ TrueClass
The empty? method checks if the Tags instance's set is empty.
-
#initialize(tags = [], source: nil) ⇒ Documentrix::Utils::Tags
constructor
The initialize method sets up the Documentrix::Utils::Tags object by processing an array of tags and adding them to the internal set.
-
#size ⇒ Integer
The size method returns the number of elements in the set.
-
#to_s(link: true) ⇒ Array<String>
The to_s method formats the tags string for output, including source URL if requested.
Constructor Details
#initialize(tags = [], source: nil) ⇒ Documentrix::Utils::Tags
The initialize method sets up the Documentrix::Utils::Tags object by processing an array of tags and adding them to the internal set.
49 50 51 52 53 |
# File 'lib/documentrix/utils/tags.rb', line 49 def initialize( = [], source: nil) = Array() @set = [] .each { |tag| add(tag, source:) } end |
Instance Method Details
#add(tag, source: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/documentrix/utils/tags.rb', line 55 def add(tag, source: nil) unless tag.is_a?(Tag) tag = Tag.new(tag, source:) end index = @set.bsearch_index { _1 >= tag } if index == nil @set.push(tag) elsif @set.at(index) != tag @set.insert(index, tag) end self end |
#clear ⇒ Documentrix::Utils::Tags
The clear method resets the Documentrix::Utils::Tags instance's set by calling its clear method.
87 88 89 90 |
# File 'lib/documentrix/utils/tags.rb', line 87 def clear @set.clear self end |
#each {|element| ... } ⇒ Documentrix::Utils::Tags
The each method iterates over this Tags instance's set and yields each tags to the given block.
98 99 100 101 |
# File 'lib/documentrix/utils/tags.rb', line 98 def each(&block) @set.each(&block) self end |
#empty? ⇒ TrueClass
The empty? method checks if the Tags instance's set is empty.
71 72 73 |
# File 'lib/documentrix/utils/tags.rb', line 71 def empty? @set.empty? end |
#size ⇒ Integer
The size method returns the number of elements in the set.
78 79 80 |
# File 'lib/documentrix/utils/tags.rb', line 78 def size @set.size end |
#to_s(link: true) ⇒ Array<String>
The to_s method formats the tags string for output, including source URL if requested.
109 110 111 |
# File 'lib/documentrix/utils/tags.rb', line 109 def to_s(link: true) @set.map { |tag| tag.to_s(link:) } * ' ' end |