Class: DribbbleBucketSync::Folder
- Inherits:
-
Object
- Object
- DribbbleBucketSync::Folder
- Defined in:
- lib/dribbble_bucket_sync/folder.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#shots ⇒ Object
readonly
Returns the value of attribute shots.
Instance Method Summary collapse
- #add_shot(shot) ⇒ Object
-
#current_shot_files ⇒ Object
returns an array of existing shot files.
-
#initialize(directory, name) ⇒ Folder
constructor
A new instance of Folder.
- #remove_old_shots ⇒ Object
Constructor Details
#initialize(directory, name) ⇒ Folder
Returns a new instance of Folder.
9 10 11 12 13 14 15 16 17 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 9 def initialize(directory, name) name = sanitize(name) # store the path @path = File.join(directory, name) # ensure our folder exists ensure_folder_exists # create storage for the shots @shots = [] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 7 def path @path end |
#shots ⇒ Object (readonly)
Returns the value of attribute shots.
7 8 9 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 7 def shots @shots end |
Instance Method Details
#add_shot(shot) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 19 def add_shot(shot) url = shot.image_url # add the file to the shots list filename = "#{shot.id}#{File.extname(url)}" @shots << filename # calculate the path path = File.join(@path, filename) # download if it doesn't exist unless File.exist?(path) download(url, path) end end |
#current_shot_files ⇒ Object
returns an array of existing shot files
43 44 45 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 43 def current_shot_files Dir.glob(File.join(@path, "*.{jpg,jpeg,png,gif}")) end |
#remove_old_shots ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/dribbble_bucket_sync/folder.rb', line 32 def remove_old_shots # loop through all shots in the folder current_shot_files.each do |file| # delete file if the shot isn't in the array unless @shots.include?(File.basename(file)) FileUtils.rm(file) end end end |