Class: Stilts::Image
- Inherits:
-
Object
- Object
- Stilts::Image
- Defined in:
- lib/stilts/image.rb
Overview
Intermediate utility class for image manipulation
Constant Summary collapse
- SLUG_ABBREVIATIONS =
{ :device_width_ratio => "dwr" }
- TRANSFORM_OPTIONS =
[ "device_width_ratio" ]
Instance Attribute Summary collapse
-
#device_width_ratio ⇒ Object
The public location of the image.
-
#source ⇒ Object
The public location of the image.
Instance Method Summary collapse
-
#cdn_url ⇒ Object
Location on server that will server this image.
- #deliver ⇒ Object
-
#initialize(source, options) ⇒ Image
constructor
:nodoc:.
-
#name ⇒ Object
The full image name, a combination of
url_id
andparams_slug
. -
#params_slug ⇒ Object
Combines resizing parameters into a short, unique slug to be appended to the final image name.
-
#to_hash ⇒ Object
A hash representation of the image attributes.
-
#to_json ⇒ Object
Ready images for transport across voidy vastness of teh interweb.
-
#url_id ⇒ Object
Generates a SHA1 represenation for a particular URL.
Constructor Details
#initialize(source, options) ⇒ Image
:nodoc:
18 19 20 21 |
# File 'lib/stilts/image.rb', line 18 def initialize(source, ) self.source = source self.device_width_ratio = [:device_width_ratio] || 1 end |
Instance Attribute Details
#device_width_ratio ⇒ Object
The public location of the image
15 16 17 |
# File 'lib/stilts/image.rb', line 15 def device_width_ratio @device_width_ratio end |
#source ⇒ Object
The public location of the image
15 16 17 |
# File 'lib/stilts/image.rb', line 15 def source @source end |
Instance Method Details
#cdn_url ⇒ Object
Location on server that will server this image
41 42 43 44 45 46 47 |
# File 'lib/stilts/image.rb', line 41 def cdn_url Stilts.configuration.protocol + "://" + Stilts.configuration.cdn_host + "/images/" + Stilts.configuration.api_key + "/" + self.name end |
#deliver ⇒ Object
49 50 51 |
# File 'lib/stilts/image.rb', line 49 def deliver Stilts.sender.send_image_transform_data("[#{self.to_json}]") end |
#name ⇒ Object
The full image name, a combination of url_id
and params_slug
36 37 38 |
# File 'lib/stilts/image.rb', line 36 def name url_id + "_" + params_slug end |
#params_slug ⇒ Object
Combines resizing parameters into a short, unique slug to be appended to the final image name
29 30 31 32 33 |
# File 'lib/stilts/image.rb', line 29 def params_slug TRANSFORM_OPTIONS.map do |option| param_slug(option) end.join("") end |
#to_hash ⇒ Object
A hash representation of the image attributes
59 60 61 62 63 64 |
# File 'lib/stilts/image.rb', line 59 def to_hash { :source => self.source, :name => self.name, } end |
#to_json ⇒ Object
Ready images for transport across voidy vastness of teh interweb
54 55 56 |
# File 'lib/stilts/image.rb', line 54 def to_json JSON.generate(self.to_hash) end |
#url_id ⇒ Object
Generates a SHA1 represenation for a particular URL
24 25 26 |
# File 'lib/stilts/image.rb', line 24 def url_id Digest::SHA1.hexdigest(self.source) end |