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
33
34
35
# File 'lib/ollama/dto.rb', line 29

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

#to_jsonObject



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

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