Class: Runoff::Chat

Inherits:
Object
  • Object
show all
Defined in:
lib/runoff/chat.rb

Overview

Public: Reads data from the SQLite database used by Skype/

Instance Method Summary collapse

Constructor Details

#initialize(db_location, options) ⇒ Chat

Public: Initializes a Chat object.

db_location - A String with a path to the database file.



11
12
13
14
# File 'lib/runoff/chat.rb', line 11

def initialize(db_location, options)
  @messages = Sequel.sqlite(db_location)[Runoff::TABLE]
  @adapter  = Object.const_get("Runoff::Adapters::#{options[:adapter]}").new
end

Instance Method Details

#get_chatname_optionsObject

Public: Creates a collection with all chats available for export.

Returns a Set with hashes e.g. [{ id: 12, name: “chatname” }, … ]



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/runoff/chat.rb', line 26

def get_chatname_options
  options = Set.new

  @messages.select(*Runoff::COLUMNS[0..1]).each do |row|
    readable_name = @adapter.parse_chatname row[Runoff::COLUMNS[1]]

    options << { id: row[Runoff::COLUMNS[0]], name: readable_name }
  end

  options
end

#get_messagesObject

Public: Returns a list of all the records in the databse.



17
18
19
20
21
# File 'lib/runoff/chat.rb', line 17

def get_messages
  @messages.select(*Runoff::COLUMNS).all.sort_by do |row|
    [row[Runoff::COLUMNS[0]], row[Runoff::COLUMNS[2]]]
  end
end