Module: Ollama::DTO

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/ollama/dto.rb', line 48

def ==(other)
  as_json == other.as_json
end

#as_array(obj) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/ollama/dto.rb', line 33

def as_array(obj)
  if obj.nil?
    obj
  elsif obj.respond_to?(:to_ary)
    obj.to_ary
  else
    [ obj ]
  end
end

#as_array_of_hashes(obj) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ollama/dto.rb', line 21

def as_array_of_hashes(obj)
  if obj.respond_to?(:to_hash)
    [ obj.to_hash ]
  elsif obj.respond_to?(:to_ary)
    obj.to_ary.map(&:to_hash)
  end
end

#as_hash(obj) ⇒ Object



29
30
31
# File 'lib/ollama/dto.rb', line 29

def as_hash(obj)
  obj&.to_hash
end

#as_jsonObject Also known as: to_hash



43
44
45
46
# File 'lib/ollama/dto.rb', line 43

def as_json(*)
  self.class.attributes.each_with_object({}) { |a, h| h[a] = send(a) }.
    reject { _2.nil? || _2.ask_and_send(:size) == 0 }
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  to_hash.empty?
end

#to_jsonObject



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

def to_json(*)
  as_json.to_json(*)
end