Class: Eventify::Database
- Inherits:
-
Object
- Object
- Eventify::Database
- Defined in:
- lib/eventify/database.rb
Constant Summary collapse
- PATH =
File.(File.join(ENV["HOME"], "/.eventify/events.sqlite3"))
Class Method Summary collapse
Class Method Details
.events ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eventify/database.rb', line 21 def events translated_events = [] sqlite.execute("select * from event") do |event| translated_events << const_get(event["provider"]).new( id: event["id"], title: event["title"], link: event["link"], date: Time.parse(event["date"]) ) end translated_events end |
.exists?(event) ⇒ Boolean
7 8 9 10 |
# File 'lib/eventify/database.rb', line 7 def exists?(event) results = sqlite.execute "select 1 from event where id=? and provider=? and link=?", [event.id, event.provider, event.link] !results.empty? end |
.save(event) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/eventify/database.rb', line 12 def save(event) sqlite.execute "insert into event values(?, ?, ?, ?, ?)", [event.id, event.provider, event.title, event.link, event.date.to_s] end |