Class: Ollama::Utils::Tags

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ollama/utils/tags.rb

Defined Under Namespace

Classes: Tag

Instance Method Summary collapse

Constructor Details

#initialize(tags = [], source: nil) ⇒ Tags

Returns a new instance of Tags.



28
29
30
31
# File 'lib/ollama/utils/tags.rb', line 28

def initialize(tags = [], source: nil)
  @set = []
  tags.each { |tag| add(tag, source:) }
end

Instance Method Details

#add(tag, source: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ollama/utils/tags.rb', line 33

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

#clearObject



54
55
56
# File 'lib/ollama/utils/tags.rb', line 54

def clear
  @set.clear
end

#each(&block) ⇒ Object



58
59
60
# File 'lib/ollama/utils/tags.rb', line 58

def each(&block)
  @set.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ollama/utils/tags.rb', line 46

def empty?
  @set.empty?
end

#sizeObject



50
51
52
# File 'lib/ollama/utils/tags.rb', line 50

def size
  @set.size
end

#to_s(link: true) ⇒ Object



63
64
65
# File 'lib/ollama/utils/tags.rb', line 63

def to_s(link: true)
  @set.map { |tag| tag.to_s(link:) } * ' '
end