Prev | Current Page 195 | Next

David Berube

"Practical Reporting with Ruby and Rails"

save
end
end
end
end
Save this script as paypal_load_data.rb.
You can run the script using the following command:
ruby paypal_load_data.rb /path/to/paypal_file.csv
Of course, replace the italicized parts with the appropriate values for your system.
Next, let??™s examine the code.
CHAPTER 7 n TRACKING EXPENDITURES WITH PAYPAL 140
Dissecting the Code
The first few lines of Listing 7-1 pull the arguments from the command line and assign
them to variables:
(puts "usage: #{$0} csv_filename";
exit) unless ARGV.length==1
paypal_source_file = ARGV.first
This code ensures that you have only one value passed to the command line. If you
have more or less than one argument, the program exits with an explanation of how the
program should be called. ($0 is a special variable referring to the name of the current
program.) You then take the single entry in your array of arguments and assign its value
to the paypal_source_file variable. This single variable specifies from which file to load
the data.
Next, you create a connection to your database:
ActiveRecord::Base.


Pages:
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
motoryzacja szkoła narciarska wyrejestrowanie samochodu legnica obciążniki Wczasy nad morzem