Module: Ollama::DTO
- Extended by:
- Tins::Concern
- Included in:
- Commands::Chat, Commands::Copy, Commands::Create, Commands::Delete, Commands::Embed, Commands::Embeddings, Commands::Generate, Commands::Pull, Commands::Push, Commands::Show, Message, Options, Tool, Tool::Function, Tool::Function::Parameters, Tool::Function::Parameters::Property
- Defined in:
- lib/ollama/dto.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #as_array_of_hashes(obj) ⇒ Object
- #as_json ⇒ Object (also: #to_hash)
- #empty? ⇒ Boolean
- #to_json ⇒ Object
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_json ⇒ Object 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
36 37 38 |
# File 'lib/ollama/dto.rb', line 36 def empty? to_hash.empty? end |
#to_json ⇒ Object
40 41 42 |
# File 'lib/ollama/dto.rb', line 40 def to_json(*) as_json.to_json(*) end |