class PhotoPartySync::Card
Represents a remote sd card - sets up connects and gets file list
Attributes
name[R]
target_base_path[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/photo_party_sync/card.rb, line 14 def initialize(name) @name = name end
Public Instance Methods
download_all()
click to toggle source
# File lib/photo_party_sync/card.rb, line 54 def download_all files.each do |file| if file.valid? && !file.exist? logger.info "Downloading #{file.name}..." unless @options[:quiet] file.download else logger.info "Skipping file #{file.name}..." end end end
files()
click to toggle source
# File lib/photo_party_sync/card.rb, line 31 def files found_files = [] folders.each do |folder| file_list = entry_list("/DCIM/#{folder}") file_list.each do |file_row| file_info = file_row.split ',' file = CardFile.new file.path = file_info[0] file.name = file_info[1] file.size = file_info[2] file.attributes = file_info[3] file.date = file_info[4].to_i file.time = file_info[5].to_i file.target_base_path = @target_base_path file.card = @name found_files << file end end found_files end
folders()
click to toggle source
# File lib/photo_party_sync/card.rb, line 22 def folders @folders ||= read_folders end
read_folders()
click to toggle source
# File lib/photo_party_sync/card.rb, line 26 def read_folders folder_list = entry_list('/DCIM') folder_list.collect { |row| row.split(',')[1] } end
ready?()
click to toggle source
# File lib/photo_party_sync/card.rb, line 18 def ready? system("ping -c 1 -t 1 '#{@name}' > /dev/null 2>&1") end
valid?()
click to toggle source
# File lib/photo_party_sync/card.rb, line 65 def valid? open("http://#{@options[:card]}/command.cgi?op=100&DIR=/DCIM") true rescue SocketError false end
Protected Instance Methods
entry_list(folder)
click to toggle source
# File lib/photo_party_sync/card.rb, line 74 def entry_list(folder) doc = Nokogiri::HTML(open("http://#{@name}/command.cgi?op=100&DIR=#{folder}", read_timeout: 2)) entries = doc.css('p').first.content.split("\n") entries.shift entries rescue StandardError => e logger.warn e.message [] end