Class: Ogo::ImageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ogo/image_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#urlObject

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_typeObject



25
26
27
# File 'lib/ogo/image_info.rb', line 25

def content_type
  "image/#{fetch_type}"
end

#fetch_sizeObject



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_typeObject



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

#heightObject



17
18
19
# File 'lib/ogo/image_info.rb', line 17

def height
  fetch_size[1]
end

#typeObject



21
22
23
# File 'lib/ogo/image_info.rb', line 21

def type
  fetch_type
end

#widthObject



13
14
15
# File 'lib/ogo/image_info.rb', line 13

def width
  fetch_size[0]
end