Class: GroqRuby::Multipart::Part

Inherits:
Data
  • Object
show all
Defined in:
lib/groq_ruby/multipart.rb

Overview

A single field inside a multipart payload.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type

Returns:

  • (Object)

    the current value of content_type



18
19
20
# File 'lib/groq_ruby/multipart.rb', line 18

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



18
19
20
# File 'lib/groq_ruby/multipart.rb', line 18

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



18
19
20
# File 'lib/groq_ruby/multipart.rb', line 18

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



18
19
20
# File 'lib/groq_ruby/multipart.rb', line 18

def value
  @value
end

Class Method Details

.file(name, io:, filename:, content_type: "application/octet-stream") ⇒ Part

Build a file upload field.

Parameters:

  • name (String)
  • io (#read)

    readable IO whose ‘#read` returns the bytes.

  • filename (String)
  • content_type (String) (defaults to: "application/octet-stream")

Returns:



33
34
35
# File 'lib/groq_ruby/multipart.rb', line 33

def self.file(name, io:, filename:, content_type: "application/octet-stream")
  new(name: name, value: io, filename: filename, content_type: content_type)
end

.text(name, value) ⇒ Part

Build a plain text field.

Parameters:

  • name (String)
  • value (#to_s)

Returns:



23
24
25
# File 'lib/groq_ruby/multipart.rb', line 23

def self.text(name, value)
  new(name: name, value: value.to_s, filename: nil, content_type: nil)
end

Instance Method Details

#file?Boolean

Returns true if this part is a file upload (has a filename).

Returns:

  • (Boolean)

    true if this part is a file upload (has a filename)



38
39
40
# File 'lib/groq_ruby/multipart.rb', line 38

def file?
  !filename.nil?
end