class EventDb::Database

Public Class Methods

new( config={} ) click to toggle source
# File lib/eventdb/database.rb, line 6
def initialize( config={} )
  @config = config
end

Public Instance Methods

add( events ) click to toggle source
# File lib/eventdb/database.rb, line 31
def add( events )
  ## todo/fix: add check if Array and also allow single event
  ##  change arg to event_or_events - why? why not?

  ## todo/fix:   use attributes or to_hash or somehting that works with ActiveRecord and Struct objects - why? why not?

  events.each do |ev|
    Model::Event.create!(
        title:      ev.title,
        link:       ev.link,
        place:      ev.place,
        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
connect() click to toggle source
# File lib/eventdb/database.rb, line 10
def connect
  ActiveRecord::Base.establish_connection( @config )
end
create() click to toggle source
# File lib/eventdb/database.rb, line 14
def create
  CreateDb.new.up
  ConfDb::Model::Prop.create!( key: 'db.schema.event.version', value: VERSION )
end
create_all() click to toggle source
# File lib/eventdb/database.rb, line 19
def create_all
  LogDb.create # add logs table
  ConfDb.create
  create
end
read( path ) click to toggle source
# File lib/eventdb/database.rb, line 26
def read( path )   ## path_or_url
  events = EventReader.read( path )
  add( events )
end