Class: Runoff::Composition

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

Overview

Public: Provides interaction with a Skype database file.

Examples

composition = Composition.new 'path/to/the/main.db'
exported_files_count = composition.export 'export/folder'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(optional_file_path, skype_username = nil) ⇒ Composition

Public: Initialize a Composition object.

main_db_file_path - A String with the path to the Skype database file. skype_username - A String with Skype login.

Raises IOError if the file cannot be found

Raises:

  • (IOError)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/runoff/composition.rb', line 21

def initialize(optional_file_path, skype_username = nil)
  main_db_file_path = optional_file_path || Runoff::Location.default_skype_data_location(skype_username)

  raise IOError, "File doesn't exist" unless File.exists? main_db_file_path

  skype_database = Sequel.connect "sqlite://#{main_db_file_path}"
  @messages = skype_database.from :Messages
  @exported_filenames = Set.new
  @format = Runoff::SkypeDataFormat.new
  @file_writer = Runoff::FileWriter.new @format
end

Instance Attribute Details

#exported_filenamesObject (readonly)

Public: Returns a Set object of all the names of the exported files.



13
14
15
# File 'lib/runoff/composition.rb', line 13

def exported_filenames
  @exported_filenames
end

Instance Method Details

#export(destination_path) ⇒ Object

Public: Reads all chat records from database and runs the export process.

destination_path - A String with folder path, where to put exported files.

Examples

export '/home/username/skype_backup'
# => 8

Returns the count of the exported files.



43
44
45
46
47
# File 'lib/runoff/composition.rb', line 43

def export(destination_path)
  chat_records = @messages.select(:chatname, :timestamp, :from_dispname, :body_xml)

  run_export chat_records, destination_path
end

#export_chats(chatnames, destination_path) ⇒ Object

Public: Exports Skype chat history to text files for specified chats.

chatnames - Array of chatnames, which will be exported destination_path - A String with folder path, where to put exported files.

Examples

export_chats ['#something/$more;', '#something/$else;'], '~/skype_backup'
# => 2

Returns the count of the exported files.



77
78
79
80
81
82
# File 'lib/runoff/composition.rb', line 77

def export_chats(chatnames, destination_path)
  pattern_chatnames = chatnames.map { |name| "#{name}%" }
  chat_records = @messages.where(Sequel.like(:chatname, *pattern_chatnames))

  run_export chat_records, destination_path
end

#get_chatnamesObject

Public: Gets parsed chatnames together with partly parsed chatnames.

Examples

get_chatnames
# => [['something-more', 'somethindg-else'],
      ['#something/$more;6521032', '#something/$else;8971263']]

Returns two Array objects containing parsed chatnames and partly parsed chatnames.



58
59
60
61
62
63
64
# File 'lib/runoff/composition.rb', line 58

def get_chatnames
  chatnames = @messages.select(:chatname)
  raw_chatnames = chatnames.map { |record| @format.partly_parse_chatname record[:chatname] }.uniq
  clean_chatnames = raw_chatnames.map { |chatname| @format.parse_chatname chatname }

  return clean_chatnames, raw_chatnames
end