Class: Ms::Generators::UnimodDb
- Inherits:
-
Tap::Generator::Base
- Object
- Tap::Generator::Base
- Ms::Generators::UnimodDb
- Defined in:
- lib/ms/generators/unimod_db.rb
Overview
:startdoc::generator generate a new unimod database
Downloads and generates a Unimod database (sqlite):
% tap generate unimod
% sqlite3 unimod.sqlite
sqlite> select * from elements;
1|H|Hydrogen|1.007825035|1.00794
2|2H|Deuterium|2.014101779|2.014101779
3|Li|Lithium|7.016003|6.941
...
The database data is downloaded from the unimod website.
Instance Method Summary collapse
Instance Method Details
#manifest(m, database = "unimod.sqlite") ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ms/generators/unimod_db.rb', line 30 def manifest(m, database="unimod.sqlite") m.file database do |db| db.close db = Sequel.sqlite(db.path) log :get, uri doc = Hpricot.XML(open(uri)) db.transaction do Ms::Unimod::TABLES.each_pair do |table_name, schema| log :create_table, table_name db.create_table(table_name, &schema) table = db[table_name] rows = doc.search("unimod/#{table_name}/#{table_name}_row") rows.each do |row| attributes = row.attributes record_id = attributes["record_id"] log(:insert, record_id) table.insert(attributes) end end end db.disconnect end end |