Class: RailsAi::ImageContext
- Inherits:
-
Object
- Object
- RailsAi::ImageContext
- Defined in:
- lib/rails_ai/image_context.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
- .extract_file_metadata(image_file) ⇒ Object
- .from_base64(image_data) ⇒ Object
- .from_file(image_file) ⇒ Object
- .from_url(image_url) ⇒ Object
Instance Method Summary collapse
- #analysis_ready? ⇒ Boolean
-
#initialize(image_data, metadata: {}) ⇒ ImageContext
constructor
A new instance of ImageContext.
- #to_h ⇒ Object
Constructor Details
#initialize(image_data, metadata: {}) ⇒ ImageContext
Returns a new instance of ImageContext.
7 8 9 10 11 12 13 14 |
# File 'lib/rails_ai/image_context.rb', line 7 def initialize(image_data, metadata: {}) @metadata = || {} @source = determine_source(image_data) @dimensions = extract_dimensions(image_data) @file_size = extract_file_size(image_data) @format = extract_format(image_data) @created_at = current_time end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def created_at @created_at end |
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def dimensions @dimensions end |
#file_size ⇒ Object (readonly)
Returns the value of attribute file_size.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def file_size @file_size end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def format @format end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def @metadata end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/rails_ai/image_context.rb', line 5 def source @source end |
Class Method Details
.extract_file_metadata(image_file) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/rails_ai/image_context.rb', line 103 def self.(image_file) { filename: image_file.respond_to?(:original_filename) ? image_file.original_filename : 'unknown', content_type: image_file.respond_to?(:content_type) ? image_file.content_type : 'unknown' } end |
.from_base64(image_data) ⇒ Object
40 41 42 |
# File 'lib/rails_ai/image_context.rb', line 40 def self.from_base64(image_data) new(image_data, metadata: { encoding: 'base64' }) end |
.from_file(image_file) ⇒ Object
32 33 34 |
# File 'lib/rails_ai/image_context.rb', line 32 def self.from_file(image_file) new(image_file, metadata: (image_file)) end |
.from_url(image_url) ⇒ Object
36 37 38 |
# File 'lib/rails_ai/image_context.rb', line 36 def self.from_url(image_url) new(image_url, metadata: { url: image_url }) end |
Instance Method Details
#analysis_ready? ⇒ Boolean
28 29 30 |
# File 'lib/rails_ai/image_context.rb', line 28 def analysis_ready? dimensions.present? && format.present? end |
#to_h ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails_ai/image_context.rb', line 16 def to_h { source: source, dimensions: dimensions, file_size: file_size, format: format, created_at: created_at.iso8601, metadata: , analysis_ready: analysis_ready? } end |