Class: Ollama::Image
- Inherits:
- 
      Object
      
        - Object
- Ollama::Image
 
- Defined in:
- lib/ollama/image.rb
Overview
Ollama::Image
Represents an image object that can be used in messages sent to the Ollama API. The Image class provides methods to create image objects from various sources including base64 encoded strings, file paths, IO objects, and raw string data.
Instance Attribute Summary collapse
- 
  
    
      #data  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The data attribute reader returns the image data stored in the object. 
- 
  
    
      #path  ⇒ String? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The path attribute stores the file path associated with the image object. 
Class Method Summary collapse
- 
  
    
      .for_base64(data, path: nil)  ⇒ Ollama::Image 
    
    
  
  
  
  
  
  
  
  
  
    Creates a new Image object from base64 encoded data. 
- 
  
    
      .for_filename(path)  ⇒ Ollama::Image 
    
    
  
  
  
  
  
  
  
  
  
    Creates a new Image object from a file path by opening the file in binary mode and passing it to the for_io method. 
- 
  
    
      .for_io(io, path: nil)  ⇒ Ollama::Image 
    
    
  
  
  
  
  
  
  
  
  
    Creates a new Image object from an IO object by reading its contents and optionally setting a path. 
- 
  
    
      .for_string(string, path: nil)  ⇒ Ollama::Image 
    
    
  
  
  
  
  
  
  
  
  
    Creates a new Image object from a string by encoding it to base64. 
Instance Method Summary collapse
- 
  
    
      #==(other)  ⇒ TrueClass, FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    The == method compares two Image objects for equality based on their data contents. 
- 
  
    
      #initialize(data)  ⇒ Image 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initializes a new Image object with the provided data. 
- 
  
    
      #to_s  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    The to_s method returns the raw image data stored in the Image object. 
Constructor Details
#initialize(data) ⇒ Image
Initializes a new Image object with the provided data.
| 26 27 28 | # File 'lib/ollama/image.rb', line 26 def initialize(data) @data = data end | 
Instance Attribute Details
#data ⇒ String (readonly)
The data attribute reader returns the image data stored in the object.
| 38 39 40 | # File 'lib/ollama/image.rb', line 38 def data @data end | 
#path ⇒ String?
The path attribute stores the file path associated with the image object.
| 33 34 35 | # File 'lib/ollama/image.rb', line 33 def path @path end | 
Class Method Details
.for_base64(data, path: nil) ⇒ Ollama::Image
Creates a new Image object from base64 encoded data.
provided data and path
| 48 49 50 51 52 | # File 'lib/ollama/image.rb', line 48 def for_base64(data, path: nil) obj = new(data) obj.path = path obj end | 
.for_filename(path) ⇒ Ollama::Image
Creates a new Image object from a file path by opening the file in binary mode and passing it to the for_io method.
contents of the file at the specified path
| 85 86 87 | # File 'lib/ollama/image.rb', line 85 def for_filename(path) File.open(path, 'rb') { |io| for_io(io, path:) } end | 
.for_io(io, path: nil) ⇒ Ollama::Image
Creates a new Image object from an IO object by reading its contents and optionally setting a path.
object’s data and optional path
| 73 74 75 76 | # File 'lib/ollama/image.rb', line 73 def for_io(io, path: nil) path ||= io.path for_string(io.read, path:) end | 
.for_string(string, path: nil) ⇒ Ollama::Image
Creates a new Image object from a string by encoding it to base64.
encoded string data and optional path
| 61 62 63 | # File 'lib/ollama/image.rb', line 61 def for_string(string, path: nil) for_base64(Base64.encode64(string), path:) end | 
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
The == method compares two Image objects for equality based on their data contents.
data, false otherwise
| 99 100 101 | # File 'lib/ollama/image.rb', line 99 def ==(other) @data == other.data end | 
#to_s ⇒ String
The to_s method returns the raw image data stored in the Image object.
| 106 107 108 | # File 'lib/ollama/image.rb', line 106 def to_s @data end |