Class: Riiif::Image
- Inherits:
-
Object
- Object
- Riiif::Image
- Defined in:
- app/models/riiif/image.rb
Constant Summary collapse
- OUTPUT_FORMATS =
%w(jpg png).freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #image ⇒ Object
- #info ⇒ Object
-
#initialize(id, file = nil) ⇒ Image
constructor
A new instance of Image.
- #render(args) ⇒ Object
Constructor Details
#initialize(id, file = nil) ⇒ Image
Returns a new instance of Image.
26 27 28 29 |
# File 'app/models/riiif/image.rb', line 26 def initialize(id, file = nil) @id = id @image = file if file.present? end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'app/models/riiif/image.rb', line 22 def id @id end |
Class Method Details
.cache_key(id, options) ⇒ Object
52 53 54 55 56 |
# File 'app/models/riiif/image.rb', line 52 def cache_key(id, ) str = .merge(id: id).delete_if { |_, v| v.nil? }.to_s # Use a MD5 digest to ensure the keys aren't too long. Digest::MD5.hexdigest(str) end |
Instance Method Details
#image ⇒ Object
31 32 33 |
# File 'app/models/riiif/image.rb', line 31 def image @image ||= file_resolver.find(id) end |
#info ⇒ Object
42 43 44 |
# File 'app/models/riiif/image.rb', line 42 def info info_service.call(id, image) end |
#render(args) ⇒ Object
35 36 37 38 39 40 |
# File 'app/models/riiif/image.rb', line 35 def render(args) = (args) Rails.cache.fetch(Image.cache_key(id, ), compress: true, expires_in: Image.expires_in) do image.extract() end end |