Class: DribbbleBucketSync::Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/dribbble_bucket_sync/folder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/dribbble_bucket_sync/folder.rb', line 7

def path
  @path
end

#shotsObject (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_filesObject

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_shotsObject



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