Class: Sunnyside::OutgoingFiles

Inherits:
SunnyFTP
  • Object
show all
Defined in:
lib/sunnyside/ftp.rb

Instance Attribute Summary collapse

Attributes inherited from SunnyFTP

#directory, #password, #username

Instance Method Summary collapse

Methods inherited from SunnyFTP

#check_for_new_files, #log_on

Constructor Details

#initialize(ftp, name) ⇒ OutgoingFiles

Returns a new instance of OutgoingFiles.



82
83
84
85
# File 'lib/sunnyside/ftp.rb', line 82

def initialize(ftp, name)
  @name = name
  @ftp  = ftp
end

Instance Attribute Details

#ftpObject (readonly)

Returns the value of attribute ftp.



80
81
82
# File 'lib/sunnyside/ftp.rb', line 80

def ftp
  @ftp
end

#nameObject (readonly)

Returns the value of attribute name.



80
81
82
# File 'lib/sunnyside/ftp.rb', line 80

def name
  @name
end

Instance Method Details

#new_filesObject



87
88
89
# File 'lib/sunnyside/ftp.rb', line 87

def new_files
  Dir["#{DRIVE}/sunnyside-files/ftp/837/#{name}/*.txt"]
end

#upload_file(file) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/sunnyside/ftp.rb', line 99

def upload_file(file)
  ftp.putbinaryfile(file)
  puts "#{file} uploaded."
  puts "Deleting local file..."
  File.delete(file)
  puts "File deleted."
end

#upload_filesObject



91
92
93
94
95
96
97
# File 'lib/sunnyside/ftp.rb', line 91

def upload_files
  if new_files.size > 0
    new_files.each { |file| upload_file(file) }
  else
    puts "No new files to upload."
  end
end