Class: ImageInfo::Image

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

Defined Under Namespace

Classes: NullUri

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Image

Returns a new instance of Image.



8
9
10
11
12
13
14
15
# File 'lib/image_info/image.rb', line 8

def initialize(uri)
  @uri        = ::Addressable::URI.parse(uri.to_s)
  @uri.scheme = 'http'  unless @uri.scheme
  @uri.port   = 80      unless @uri.port
  @uri.normalize!
rescue ::Addressable::URI::InvalidURIError
  @uri = NullUri.new
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/image_info/image.rb', line 6

def height
  @height
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/image_info/image.rb', line 6

def type
  @type
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/image_info/image.rb', line 5

def uri
  @uri
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/image_info/image.rb', line 6

def width
  @width
end

Instance Method Details

#sizeObject



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

def size
  [width, height].compact
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  !!uri.host
end