Class: Viberator::Database
- Inherits:
-
Object
- Object
- Viberator::Database
- Defined in:
- lib/viberator/database.rb
Instance Method Summary collapse
- #author(number) ⇒ Object
- #chats ⇒ Object
- #events(chat_id) ⇒ Object
-
#initialize(viberator, path) ⇒ Database
constructor
A new instance of Database.
- #name ⇒ Object
- #sticker(id) ⇒ Object
Constructor Details
#initialize(viberator, path) ⇒ Database
Returns a new instance of Database.
12 13 14 15 16 |
# File 'lib/viberator/database.rb', line 12 def initialize(viberator, path) @viberator = viberator @path = Pathname.new path @connection = Sequel.connect "sqlite://#{@path.join "viber.db"}" end |
Instance Method Details
#author(number) ⇒ Object
33 34 35 36 |
# File 'lib/viberator/database.rb', line 33 def (number) attrs = @connection[:OriginNumberInfo].where(:Number => number).first Author.new(self, attrs || { :Number => number }) end |
#chats ⇒ Object
22 23 24 |
# File 'lib/viberator/database.rb', line 22 def chats @connection[:ChatInfo].map { |attrs| Chat.new(self, attrs) } end |
#events(chat_id) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/viberator/database.rb', line 26 def events(chat_id) @connection[:EventInfo] .where(:ChatID => chat_id) .order(:TimeStamp) .map { |attrs| Event.new(self, attrs) } end |
#name ⇒ Object
18 19 20 |
# File 'lib/viberator/database.rb', line 18 def name @path.basename.to_s end |
#sticker(id) ⇒ Object
38 39 40 |
# File 'lib/viberator/database.rb', line 38 def sticker(id) @viberator.sticker id end |