Class: ThumbnailScraper::Image

Inherits:
Object
  • Object
show all
Includes:
WithSmartUrl
Defined in:
lib/thumbnail_scraper/image.rb

Instance Method Summary collapse

Methods included from WithSmartUrl

#url, #url=

Constructor Details

#initialize(url) ⇒ Image

Returns a new instance of Image.



8
9
10
# File 'lib/thumbnail_scraper/image.rb', line 8

def initialize(url)
  self.url = url
end

Instance Method Details

#areaObject



28
29
30
# File 'lib/thumbnail_scraper/image.rb', line 28

def area
  width * height
end

#exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/thumbnail_scraper/image.rb', line 12

def exists?
  size ? true : false
end

#heightObject



24
25
26
# File 'lib/thumbnail_scraper/image.rb', line 24

def height
  size[1]
end

#sizeObject



16
17
18
# File 'lib/thumbnail_scraper/image.rb', line 16

def size
  @size ||= ::FastImage.size(url.to_s)
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/thumbnail_scraper/image.rb', line 32

def valid?
  width >= 50 && height >= 50 && width.to_f / height.to_f <= 3 && height.to_f / width.to_f <= 3
end

#widthObject



20
21
22
# File 'lib/thumbnail_scraper/image.rb', line 20

def width
  size[0]
end