Class: Ogo::ImageInfo
- Inherits:
-
Object
- Object
- Ogo::ImageInfo
- Defined in:
- lib/ogo/image_info.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #content_type ⇒ Object
- #fetch_size ⇒ Object
- #fetch_size! ⇒ Object
- #fetch_type ⇒ Object
- #fetch_type! ⇒ Object
- #height ⇒ Object
-
#initialize(opts = {}) ⇒ ImageInfo
constructor
A new instance of ImageInfo.
- #type ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ImageInfo
Returns a new instance of ImageInfo.
6 7 8 9 10 11 |
# File 'lib/ogo/image_info.rb', line 6 def initialize(opts={}) @url = opts[:url] @width = opts[:width] @height = opts[:height] @type = opts[:type] end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/ogo/image_info.rb', line 4 def url @url end |
Instance Method Details
#content_type ⇒ Object
25 26 27 |
# File 'lib/ogo/image_info.rb', line 25 def content_type "image/#{fetch_type}" end |
#fetch_size ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/ogo/image_info.rb', line 29 def fetch_size return [@width, @height] if @width && @height if defined?(FastImage) @width, @height = fi_check(:size, url) else [] end end |
#fetch_size! ⇒ Object
38 39 40 41 |
# File 'lib/ogo/image_info.rb', line 38 def fetch_size! @width, @height = nil fetch_size end |
#fetch_type ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ogo/image_info.rb', line 43 def fetch_type @type ||= \ if defined?(FastImage) fi_check(:type, url).to_s else uri = Addressable::URI.parse(url).normalize if uri.path.include?('.') uri.path.split('.').last.to_s end end end |
#fetch_type! ⇒ Object
55 56 57 58 |
# File 'lib/ogo/image_info.rb', line 55 def fetch_type! @type = nil fetch_type end |
#height ⇒ Object
17 18 19 |
# File 'lib/ogo/image_info.rb', line 17 def height fetch_size[1] end |
#type ⇒ Object
21 22 23 |
# File 'lib/ogo/image_info.rb', line 21 def type fetch_type end |
#width ⇒ Object
13 14 15 |
# File 'lib/ogo/image_info.rb', line 13 def width fetch_size[0] end |