class PhotoPartySync::CardFile
Provides access to a single file on the remote sd card
Constants
- BASE_PATH
- DAY_MASK
- HOUR_MASK
- MINUTE_MASK
- MONTH_MASK
- SECOND_MASK
- YEAR_MASK
Attributes
attributes[RW]
card[RW]
date[R]
name[RW]
path[RW]
size[RW]
target_base_path[RW]
time[R]
Public Class Methods
new()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 19 def initialize @path = '' @name = '' @size = '' @attributes = '' @card = '' @target_base_path = BASE_PATH end
Public Instance Methods
create_directories()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 76 def create_directories FileUtils.mkdir_p(File.dirname(temp_path)) unless Dir.exist?(File.dirname(temp_path)) FileUtils.mkdir_p(File.dirname(local_path)) unless Dir.exist?(File.dirname(local_path)) end
date=(bits)
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 44 def date=(bits) year = 1980 + ((bits & CardFile::YEAR_MASK) >> 9) month = (bits & CardFile::MONTH_MASK) >> 5 day = (bits & CardFile::DAY_MASK) @date = "#{year}-#{month.to_s.rjust(2, '0')}-#{day.to_s.rjust(2, '0')}" end
download()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 66 def download # logger.info "Downloading: http://#{card}#{path}/#{name}" create_directories continue = File.exist?(temp_path) ? ' --continue' : '' timeout = ' --timeout=5 --tries=1 --dns-timeout=1' success = system("wget 'http://#{card}#{path}/#{name}' -O '#{temp_path}'#{continue}#{timeout}") FileUtils.mv(temp_path, local_path) if success success end
exist?()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 58 def exist? File.exist?(local_path) end
local_filename()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 32 def local_filename "#{@date}_#{@time}_#{@card}" + File.extname(@name).downcase end
local_path()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 40 def local_path @target_base_path + "/#{card}/#{local_filename}" end
temp_path()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 36 def temp_path "temp/#{@card}/#{local_filename}" end
time=(bits)
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 51 def time=(bits) hour = (bits & CardFile::HOUR_MASK) >> 11 minute = (bits & CardFile::MINUTE_MASK) >> 5 second = (bits & CardFile::SECOND_MASK) @time = "#{hour.to_s.rjust(2, '0')}-#{minute.to_s.rjust(2, '0')}-#{second.to_s.rjust(2, '0')}" end
to_s()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 28 def to_s "#{@path}/#{@name} (#{@size} Bytes, #{@date} #{@time})" end
valid?()
click to toggle source
# File lib/photo_party_sync/cardfile.rb, line 62 def valid? File.extname(@name).downcase == '.jpg' && @name.upcase != 'FA000001.JPG' end