define do
create_table AdResults.table_name do |t|
first_row.attributes.each do |attribute_name, value|
if field_override_types.include?(attribute_name)
t.column attribute_name, field_override_types[attribute_name]
else
t.column attribute_name, :text, :length=>25
end
end
end
end
end
This code pulls out the first extracted row of your data and uses it as a template to
create a schema for your table. For each attribute of the row, you add a column to your
table with that attribute??™s name. The default type for each column is a text field with a
length of 25, but you also have a field_override_types hash. If an attribute name is present
in that hash, the new type is used instead. As a result, if Google AdWords adds a new
column to the XML schema, this script will adjust.
In fact, the only parts of the entire script that are specific to this schema are the name
of the model, AdResult, the field_override_types hash, and the "table/rows/rows" selector.
If you change those elements, you can load many different types of XML using a script
like this.
Pages:
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383