Class: AILabTools::FileInput
- Inherits:
-
Object
- Object
- AILabTools::FileInput
- Defined in:
- lib/ailabtools/file_input.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Class Method Summary collapse
- .from_bytes(bytes, filename:, content_type: "application/octet-stream") ⇒ Object
- .from_io(io, filename:, content_type: "application/octet-stream") ⇒ Object
- .from_path(path, content_type: "application/octet-stream") ⇒ Object
Instance Method Summary collapse
-
#initialize(bytes:, filename:, content_type: "application/octet-stream") ⇒ FileInput
constructor
A new instance of FileInput.
Constructor Details
#initialize(bytes:, filename:, content_type: "application/octet-stream") ⇒ FileInput
Returns a new instance of FileInput.
7 8 9 10 11 12 13 |
# File 'lib/ailabtools/file_input.rb', line 7 def initialize(bytes:, filename:, content_type: "application/octet-stream") raise ArgumentError, "filename must not be empty" if filename.nil? || filename.empty? @bytes = bytes.b @filename = filename @content_type = content_type end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
5 6 7 |
# File 'lib/ailabtools/file_input.rb', line 5 def bytes @bytes end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/ailabtools/file_input.rb', line 5 def content_type @content_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/ailabtools/file_input.rb', line 5 def filename @filename end |
Class Method Details
.from_bytes(bytes, filename:, content_type: "application/octet-stream") ⇒ Object
19 20 21 |
# File 'lib/ailabtools/file_input.rb', line 19 def self.from_bytes(bytes, filename:, content_type: "application/octet-stream") new(bytes: bytes, filename: filename, content_type: content_type) end |
.from_io(io, filename:, content_type: "application/octet-stream") ⇒ Object
23 24 25 |
# File 'lib/ailabtools/file_input.rb', line 23 def self.from_io(io, filename:, content_type: "application/octet-stream") new(bytes: io.read, filename: filename, content_type: content_type) end |
.from_path(path, content_type: "application/octet-stream") ⇒ Object
15 16 17 |
# File 'lib/ailabtools/file_input.rb', line 15 def self.from_path(path, content_type: "application/octet-stream") new(bytes: File.binread(path), filename: File.basename(path), content_type: content_type) end |