Module: Ollama::DTO

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#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_jsonObject Also known as: to_hash



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

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)


36
37
38
# File 'lib/ollama/dto.rb', line 36

def empty?
  to_hash.empty?
end

#to_jsonObject



40
41
42
# File 'lib/ollama/dto.rb', line 40

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