Class: ImageCollection
- Inherits:
-
Object
- Object
- ImageCollection
- Defined in:
- lib/artbase/collection/image.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #download_images(range = (0...@count)) ⇒ Object
-
#initialize(slug, count, image_base:) ⇒ ImageCollection
constructor
A new instance of ImageCollection.
Constructor Details
#initialize(slug, count, image_base:) ⇒ ImageCollection
Returns a new instance of ImageCollection.
7 8 9 10 11 12 |
# File 'lib/artbase/collection/image.rb', line 7 def initialize( slug, count, image_base: ) # check: rename count to items or such - why? why not? @slug = slug @count = count @image_base = image_base end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/artbase/collection/image.rb', line 5 def count @count end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
5 6 7 |
# File 'lib/artbase/collection/image.rb', line 5 def slug @slug end |
Instance Method Details
#download_images(range = (0...@count)) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/artbase/collection/image.rb', line 14 def download_images( range=(0...@count) ) start = Time.now delay_in_s = 0.3 range.each do |offset| image_src = @image_base.sub( '{id}', offset.to_s ) puts "==> #{offset} - #{@slug}..." ## note: will auto-add format file extension (e.g. .png, .jpg) ## depending on http content type!!!!! copy_image( image_src, "./#{@slug}/image-i/#{offset}" ) stop = Time.now diff = stop - start mins = diff / 60 ## todo - use floor or such? secs = diff % 60 puts "up #{mins} mins #{secs} secs (total #{diff} secs)" puts "sleeping #{delay_in_s}s..." sleep( delay_in_s ) end end |