Class: ThumbnailScraper::Image
- Inherits:
-
Object
- Object
- ThumbnailScraper::Image
- Includes:
- WithSmartUrl
- Defined in:
- lib/thumbnail_scraper/image.rb
Instance Method Summary collapse
- #area ⇒ Object
- #exists? ⇒ Boolean
- #height ⇒ Object
-
#initialize(url) ⇒ Image
constructor
A new instance of Image.
- #size ⇒ Object
- #valid? ⇒ Boolean
- #width ⇒ Object
Methods included from WithSmartUrl
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
#area ⇒ Object
28 29 30 |
# File 'lib/thumbnail_scraper/image.rb', line 28 def area width * height end |
#exists? ⇒ Boolean
12 13 14 |
# File 'lib/thumbnail_scraper/image.rb', line 12 def exists? size ? true : false end |
#height ⇒ Object
24 25 26 |
# File 'lib/thumbnail_scraper/image.rb', line 24 def height size[1] end |
#size ⇒ Object
16 17 18 |
# File 'lib/thumbnail_scraper/image.rb', line 16 def size @size ||= ::FastImage.size(url.to_s) end |
#valid? ⇒ 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 |
#width ⇒ Object
20 21 22 |
# File 'lib/thumbnail_scraper/image.rb', line 20 def width size[0] end |