This approach can also be used for quick scripts outside Rails applications.
Of course, there??™s nothing preventing you from using standard Rails migrations.
Next, the code parses your input XML:
hpricot_doc = Hpricot.XML(ARGF)
rows=(hpricot_doc/"table/rows/row")
CHAPTER 13 n TRACKING YOUR ADS WITH GOOGLE ADWORDS 270
The first line creates an HTML document from the special ARGF variable. This variable
acts like a File object, but automatically refers to either one or more files passed on the
command line or to standard input if a file is not specified. In other words, the following
commands are equivalent:
ruby google_adwords_loader.rb google_sample_report.xml
ruby google_adwords_loader.rb < google_sample_report.xml
cat google_sample_report.xml | ruby google_adwords_loader.rb
If you aren??™t familar with shell redirection, you can treat ARGF as if it simply lets you
read from the file or files specified on the command line.
The second line divides the hpricot_doc object by "table/rows/rows". This looks for
any table elements containing rows elements and returns any row element that they
contain.
Pages:
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385