runoff 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +29 -15
- data/README.md +9 -3
- data/bin/runoff +26 -53
- data/lib/runoff/adapters/adapter.rb +31 -0
- data/lib/runoff/adapters/json_adapter.rb +88 -0
- data/lib/runoff/adapters/txt_adapter.rb +69 -0
- data/lib/runoff/chat.rb +38 -0
- data/lib/runoff/commandline/all.rb +53 -0
- data/lib/runoff/commandline/command.rb +34 -0
- data/lib/runoff/commandline/none.rb +45 -0
- data/lib/runoff/commandline/some.rb +84 -0
- data/lib/runoff/file_writer.rb +37 -58
- data/lib/runoff/location.rb +23 -20
- data/lib/runoff/version.rb +1 -1
- data/lib/runoff.rb +12 -4
- data/runoff.gemspec +0 -1
- data/test/command_all_test.rb +90 -0
- data/test/command_some_test.rb +49 -0
- data/test/data/custom_location/test_main.db +0 -0
- data/test/data/test_main.db +0 -0
- data/test/location_test.rb +78 -0
- metadata +21 -25
- data/lib/runoff/commands/all.rb +0 -22
- data/lib/runoff/commands/command.rb +0 -19
- data/lib/runoff/commands/some.rb +0 -38
- data/lib/runoff/skype_data_format.rb +0 -128
- data/test/skype_data_format_test.rb +0 -58
- data/test/test_db.sqlite +0 -0
@@ -1,128 +0,0 @@
|
|
1
|
-
module Runoff
|
2
|
-
# Defines methods to hide the specific format that is used in the Skype database.
|
3
|
-
class SkypeDataFormat
|
4
|
-
# Public: Defines what kind of information can be queried from the database.
|
5
|
-
#
|
6
|
-
# Example
|
7
|
-
#
|
8
|
-
# get_schema do |table, columns|
|
9
|
-
# # SELSECT *columns FROM table
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# get_schema
|
13
|
-
# # => { table: :Messages, columns: [:chatname, :timestamp, :from_dispname, :body_xml] }
|
14
|
-
#
|
15
|
-
# Returns a hash with keys "table" and "columns" if no block is given.
|
16
|
-
def get_schema
|
17
|
-
if block_given?
|
18
|
-
yield :Messages, [:chatname, :timestamp, :from_dispname, :body_xml]
|
19
|
-
else
|
20
|
-
return {
|
21
|
-
table: :Messages,
|
22
|
-
columns: [:chatname, :timestamp, :from_dispname, :body_xml]
|
23
|
-
}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Public: Provides a filename and the data that should be written to the file.
|
28
|
-
#
|
29
|
-
# fields - an array representing a single entry in the database.
|
30
|
-
#
|
31
|
-
# Examples
|
32
|
-
#
|
33
|
-
# build_entry {
|
34
|
-
# chatname: "#john/$doe;1243435",
|
35
|
-
# from_dispname: "John",
|
36
|
-
# body_xml: "Lorem ipsum",
|
37
|
-
# timestamp: 12435463
|
38
|
-
# } # => { filename: john-doe.txt, content: "[2013-12-27 12:23:43] John: Lorem ipsum" }
|
39
|
-
#
|
40
|
-
# Returns a hash with "filename" and "content" keys.
|
41
|
-
def build_entry(fields)
|
42
|
-
chatname = fields[:chatname]
|
43
|
-
username = fields[:from_dispname]
|
44
|
-
message = parse_xml fields[:body_xml]
|
45
|
-
datetime = Time.at(fields[:timestamp]).strftime "%Y-%m-%d %H:%M:%S"
|
46
|
-
|
47
|
-
{
|
48
|
-
filename: get_filename(chatname),
|
49
|
-
content: "[#{datetime}] #{username}: #{message}\n"
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
# Public: Parse a into a human readable format.
|
54
|
-
#
|
55
|
-
# chatname - a string that must be normalized.
|
56
|
-
#
|
57
|
-
# Examples
|
58
|
-
#
|
59
|
-
# normalize "#john/$doe;2354657"
|
60
|
-
# # => john-doe
|
61
|
-
#
|
62
|
-
# Returns a string without unnecessary characters.
|
63
|
-
def normalize(chatname)
|
64
|
-
pattern = /^#(.+)\/\$(.+)?;.*$/
|
65
|
-
initiator, respondent = chatname.match(pattern).captures
|
66
|
-
|
67
|
-
"#{initiator}-#{respondent}".gsub(/(^-+|-+$)/, '')
|
68
|
-
end
|
69
|
-
|
70
|
-
# Public: Converts a string that is similar to the chat title stored
|
71
|
-
# in the Skype database.
|
72
|
-
#
|
73
|
-
# dispname - a string that is displayed to the user as a chat title.
|
74
|
-
#
|
75
|
-
# Examples
|
76
|
-
#
|
77
|
-
# denormalize "john-doe"
|
78
|
-
# # => "#john/$doe;"
|
79
|
-
#
|
80
|
-
# Returns a string that can be used to query Skype database.
|
81
|
-
def denormalize(dispname)
|
82
|
-
parts = dispname.split '-'
|
83
|
-
|
84
|
-
parts.count == 2 ? "##{parts[0]}/$#{parts[1]};" : "##{parts[0]}/$;"
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
# Internal: Parses a string into a valid file name.
|
90
|
-
#
|
91
|
-
# chatname - a string that must be converted into a valid filename.
|
92
|
-
#
|
93
|
-
# Examples
|
94
|
-
#
|
95
|
-
# get_filename "#john/$doe;2354657"
|
96
|
-
# # => john-doe.txt
|
97
|
-
#
|
98
|
-
# Returns a string that can be used as a file name.
|
99
|
-
def get_filename(chatname)
|
100
|
-
normalize(chatname) + ".txt"
|
101
|
-
end
|
102
|
-
|
103
|
-
# Internal: removes unnecessary XML code from the message.
|
104
|
-
#
|
105
|
-
# message - a string to parse
|
106
|
-
#
|
107
|
-
# Examples
|
108
|
-
#
|
109
|
-
# parse_xml "<ss type="smile">:)</ss>"
|
110
|
-
# # => ":)"
|
111
|
-
#
|
112
|
-
# Returns an XML-free string.
|
113
|
-
def parse_xml(message)
|
114
|
-
if message
|
115
|
-
message = message.gsub /<ss type=".*">/, ''
|
116
|
-
message = message.gsub /<\/ss>/, ''
|
117
|
-
message = message.gsub /<a href=".*">/, ''
|
118
|
-
message = message.gsub /<\/a>/, ''
|
119
|
-
message = message.gsub /'/, "'"
|
120
|
-
message = message.gsub /</, '<'
|
121
|
-
message = message.gsub />/, '>'
|
122
|
-
message = message.gsub /"/, '"'
|
123
|
-
end
|
124
|
-
|
125
|
-
message
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'runoff'
|
3
|
-
|
4
|
-
describe Runoff::SkypeDataFormat do
|
5
|
-
before do
|
6
|
-
@format = Runoff::SkypeDataFormat.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "must return a schema of the necessary data" do
|
10
|
-
expected = { table: :Messages, columns: [:chatname, :timestamp, :from_dispname, :body_xml] }
|
11
|
-
|
12
|
-
@format.get_schema.must_equal expected
|
13
|
-
end
|
14
|
-
|
15
|
-
it "must yield a schema of the necessary data to a block" do
|
16
|
-
@format.get_schema do |table, columns|
|
17
|
-
table.must_equal :Messages
|
18
|
-
columns.must_equal [:chatname, :timestamp, :from_dispname, :body_xml]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "must return a hash with 'filename' and 'content' keys based on the input data" do
|
23
|
-
fields = {
|
24
|
-
chatname: "#john/$doe;1243435",
|
25
|
-
from_dispname: "John",
|
26
|
-
body_xml: "Lorem ipsum",
|
27
|
-
timestamp: 1387756800
|
28
|
-
}
|
29
|
-
|
30
|
-
expected = { filename: "john-doe.txt", content: "[2013-12-23 02:00:00] John: Lorem ipsum\n" }
|
31
|
-
|
32
|
-
@format.build_entry(fields).must_equal expected
|
33
|
-
end
|
34
|
-
|
35
|
-
it "must normalize a Skype specific chat title into a human readable string" do
|
36
|
-
@format.normalize('#john/$doe;2354657').must_equal 'john-doe'
|
37
|
-
end
|
38
|
-
|
39
|
-
it "must normalize a Skype specific chat title into a human readable string even in case of invalid title" do
|
40
|
-
@format.normalize('#john/$;2354657').must_equal 'john'
|
41
|
-
end
|
42
|
-
|
43
|
-
it "must parse a Skype specific chat title into a valid file name" do
|
44
|
-
@format.send(:get_filename, '#john/$doe;2354657').must_equal 'john-doe.txt'
|
45
|
-
end
|
46
|
-
|
47
|
-
it "must parse a Skype specific chat title into a valid file name even in case of invalid title" do
|
48
|
-
@format.send(:get_filename, '#john/$;2354657').must_equal 'john.txt'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "must denormalize a human readable chat title into a string that can be used in a database query" do
|
52
|
-
@format.denormalize('john-doe').must_equal '#john/$doe;'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "must denormalize a human readable, invalid chat title into a string that can be used in a database query" do
|
56
|
-
@format.denormalize('john').must_equal '#john/$;'
|
57
|
-
end
|
58
|
-
end
|
data/test/test_db.sqlite
DELETED
Binary file
|