Class: Runoff::Location

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

Overview

Contains class methods for finding out the appropriate file paths.

Examples

Location.default_skype_data_location skype_username
# => /home/user/.Skype/skype_username/main.db

Class Method Summary collapse

Class Method Details

.default_skype_data_location(skype_username) ⇒ Object

Public: Composes the default Skype database location depending on the operating system.

skype_username - A String that contains a username of the Skype account,

which database we want to access.

Examples

On Linux:
default_skype_data_location skype_username
# => /home/user/.Skype/skype_username/main.db

On Windows:
default_skype_data_location skype_username
# =>  /Users/user/AppData/Roaming/Skype/skype_username/main.db

On Mac OS:
default_skype_data_location skype_username
# =>  /Users/user/Library/Application\ Support/Skype/skype_username/main.db

Returns a String that contains the path to the Skype database file.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/runoff/location.rb', line 57

def self.default_skype_data_location(skype_username)
  case RbConfig::CONFIG['host_os']
  when /mingw/
    if File.exist?("#{ENV['APPDATA']}\\Skype")
      format_windows_path "#{ENV['APPDATA']}\\Skype\\#{skype_username}\\main.db"
    else
      format_windows_path self.get_default_skype_data_location_on_windows_8(skype_username)
    end
  when /linux/
    "#{ENV['HOME']}/.Skype/#{skype_username}/main.db"
  else
    "#{ENV['HOME']}/Library/Application Support/Skype/#{skype_username}/main.db"
  end
end

.format_windows_path(path) ⇒ Object

Public: Replaces backslashes with forward slashes and removes drive letter.

path - A String containing a directory path.

Examples

format_windows_path 'C:\Users\username\AppData\Roaming\Skype\skype_username\main.db'
# => /Users/username/AppData/ROaming/Skype/skype_username/main.db

Returns a String with modified directory path.



96
97
98
99
# File 'lib/runoff/location.rb', line 96

def self.format_windows_path(path)
  path = path.gsub(/\\/, '/')
  path.gsub(/^[a-zA-Z]:/, '')
end

.get_database_path(args, options) ⇒ Object

Public: Gets a path to the Skype main.db file.

args - An Array of commandline arguments, which might contain a String

with the Skype username.

options - A hash containing commandline options passed to the command.

If the username is empty, then the hash must contain :from key.

Examples

get_database_path('john_doe', {})
# => Path to the default Skype database location depending on the operating system.

get_database_path('', { from: '~/Desktop/main.db' })
# => '/Users/username/Desktop/main.db'

Returns a String



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

def self.get_database_path(args, options)
  if options.key?(:from)
    options[:from]
  elsif args.count > 0
    self.default_skype_data_location args[0]
  else
    raise ArgumentError, 'No username or database file path provided.'
  end
end

.get_default_skype_data_location_on_windows_8(skype_username) ⇒ Object

Public: Composes the default Skype database location for the Windows 8 operating system.

skype_username - A String that contains a username of the Skype account,

which database we want to access.

Examples

get_default_skype_data_location_on_windows_8 skype_username
# => C:/Users/user/AppData/Local/Packages/Microsoft.SkypeApp_sakjhds8asd/LocalState/skype_username/main.db

Returns a String that contains the path to the Skype database file.



112
113
114
115
116
117
118
119
# File 'lib/runoff/location.rb', line 112

def self.get_default_skype_data_location_on_windows_8(skype_username)
  location = "#{ENV['HOME']}/AppData/Local/Packages"
  skype_folder = Dir["#{location}/Microsoft.SkypeApp*"].first

  raise IOError.new "The default Skype directory doesn't exist." unless skype_folder

  "#{skype_folder}/LocalState/#{skype_username}/main.db"
end

.get_export_path(options) ⇒ Object

Public: Composes a path where the exported files must be saved.

options - A Hash with command line options passed to the runoff executable.

Returns a string with a directory path.



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

def self.get_export_path(options)
  path = options[:destination] || "#{ENV['HOME']}"
  path = "#{path}/skype_chat_history"

  FileUtils::mkdir_p path unless File.exist?(path)

  path
end