Class: EventDb::Database
- Inherits:
-
Object
- Object
- EventDb::Database
- Defined in:
- lib/eventdb/database.rb
Instance Method Summary collapse
- #add(events) ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/eventdb/database.rb', line 7 def initialize ## connect ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ':memory:' ) LogDb.create # add logs table ConfDb.create CreateDb.new.up ConfDb::Model::Prop.create!( key: 'db.schema.event.version', value: VERSION ) end |
Instance Method Details
#add(events) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/eventdb/database.rb', line 21 def add( events ) events.each do |ev| ## note: extract title from first (markdown) link m = (ev.title =~ /^\[([^\]]+)\]/) if m title = $1 puts " adding #{title} #{ev.start_date.year}, #{ev.date}" else puts "warn: cannot find event title in #{ev.title}" next # skip record; todo: issue error end Model::Event.create!( title: title, place: ev.place, date: ev.date, start_date: ev.start_date, end_date: ev.end_date, ## note: (pre)calculate duration in days ## -- mjd == Modified Julian Day Number ## -- note: 0 = same day (end==start), thus always add plus one (for one day event) days: ev.end_date.mjd - ev.start_date.mjd + 1 ) end end |