tbr 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/lib/logo.jpg +0 -0
- data/lib/tbr.rb +18 -0
- data/lib/tbr/call_detail.rb +24 -0
- data/lib/tbr/call_type.rb +23 -0
- data/lib/tbr/create_files.rb +176 -0
- data/lib/tbr/group.rb +22 -0
- data/lib/tbr/groups.rb +25 -0
- data/lib/tbr/parse_files.rb +96 -0
- data/lib/tbr/processor.rb +131 -0
- data/lib/tbr/service.rb +42 -0
- data/lib/tbr/service_summary.rb +41 -0
- data/lib/tbr/services.rb +33 -0
- data/lib/tbr/version.rb +3 -0
- data/r +1 -0
- data/spec/call_detail_spec.rb +22 -0
- data/spec/call_type_spec.rb +25 -0
- data/spec/create_files_spec.rb +83 -0
- data/spec/data/bills.csv +372 -0
- data/spec/data/call_types.csv +4 -0
- data/spec/data/empty.csv +0 -0
- data/spec/data/invalid.csv +1 -0
- data/spec/data/readonly.log +0 -0
- data/spec/data/services.csv +14 -0
- data/spec/data/test_logo.jpg +0 -0
- data/spec/group_spec.rb +43 -0
- data/spec/groups_spec.rb +59 -0
- data/spec/parse_files_spec.rb +86 -0
- data/spec/processor_spec.rb +129 -0
- data/spec/service_spec.rb +103 -0
- data/spec/service_summary_spec.rb +32 -0
- data/spec/services_spec.rb +72 -0
- data/spec/spec_helper.rb +19 -0
- data/tbr.gemspec +43 -0
- metadata +199 -0
data/spec/data/empty.csv
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
invalid services file
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
0353321261,Adrian,105 Dana St Office ISDN2,,,ISDN 2,,,
|
2
|
+
0353321492,Adrian,105 Dana St Office ISDN2,,,ISDN 2,,,
|
3
|
+
0353321676,Adrian,105 Dana St Office ISDN2,,,ISDN 2,,,
|
4
|
+
0353321689,Adrian,105 Dana St Office ISDN2,,,ISDN 2,,,
|
5
|
+
0353321286,Adrian,105 Dana St Office ISDN2. Main number.,,,ISDN 2,,,
|
6
|
+
0353321055,Adrian,105 Dana St: Fax,,,Fax/FaxStream,,,
|
7
|
+
0418133125,Cliff,Cliff Barclay,,4.99,MobileNet,,,
|
8
|
+
0428959211,Cliff,Cliff Barclay: iPad,,4.99 + 3gb @ 39.00,MobileNet,Has a $39-3GB datapack. Price for data pack seems wrong.,,
|
9
|
+
0353335856,Unknown,105 Dana St. Extension of 03 5332 1286. Redirecting from 1300792273.,,,Telephone,Maybe suspend. Used for 1300 number.,,
|
10
|
+
0353344129,Unknown,121 Albert St: Unknown Fax Line,,,Telephone,,,
|
11
|
+
0353392988,Unknown,15 Violet Grove. Wendouree: Unknown Phone,,,Telephone,,,
|
12
|
+
0398763692,Unknown,5 Dalry Avenue. Orchards. Listed as Mars Confectionary.,,Unknown. No calls Nov 2012. ,Telephone,Block and cancel if no issues.,,
|
13
|
+
0353347857,Unknown,79 Mahers Road. Warrenheip. Unknown phone.,,,ISDN 2 Enhanced,Number unavailable Nov 2012.,,
|
14
|
+
0353319583,Unknown,CENTEL. Held for call diversion to 0353348166,,,Telephone,21 calls Nov 2012. Held for call diversion to 0353348166.,,
|
Binary file
|
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
NAME = 'name'
|
4
|
+
SERVICE = 'mock service'
|
5
|
+
|
6
|
+
describe Group do
|
7
|
+
|
8
|
+
let(:group) { Group.new(NAME) }
|
9
|
+
|
10
|
+
describe ".initialize" do
|
11
|
+
it "should create an empty group array" do
|
12
|
+
expect(group.size).to eq 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#add_service" do
|
17
|
+
it "should add a service" do
|
18
|
+
group.add_service(SERVICE)
|
19
|
+
expect(group.size).to eq 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#name" do
|
24
|
+
it "should return initial name" do
|
25
|
+
expect(group.name).to eq NAME
|
26
|
+
end
|
27
|
+
|
28
|
+
it "shouldn't set name" do
|
29
|
+
expect { group.name = 'new name' }.to raise_error NoMethodError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#each" do
|
34
|
+
it "should return two groups" do
|
35
|
+
count = 0
|
36
|
+
group.add_service(SERVICE)
|
37
|
+
group.add_service(SERVICE)
|
38
|
+
group.each { count += 1}
|
39
|
+
expect(count).to eq 2
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/spec/groups_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Groups do
|
4
|
+
|
5
|
+
let(:groups) { Groups.new }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
groups.group ONE
|
9
|
+
groups.group TWO
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#size" do
|
13
|
+
it "should contain two groups" do
|
14
|
+
expect(groups.size).to eq 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#group" do
|
19
|
+
it "should return a Service" do
|
20
|
+
group = groups.group ONE
|
21
|
+
expect(group.class).to eq Group
|
22
|
+
end
|
23
|
+
|
24
|
+
context "no group number" do
|
25
|
+
it "shouldn't add nil group number" do
|
26
|
+
groups.group(nil)
|
27
|
+
expect(groups.size).to eq 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "shouldn't add empty group number" do
|
31
|
+
groups.group('')
|
32
|
+
expect(groups.size).to eq 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "pre-existing group number" do
|
37
|
+
it "shouldn't add a group" do
|
38
|
+
groups.group ONE
|
39
|
+
expect(groups.size).to eq 2
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "new group number" do
|
44
|
+
it "should add a group" do
|
45
|
+
groups.group THREE
|
46
|
+
expect(groups.size).to eq 3
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#each" do
|
52
|
+
it "should return two groups" do
|
53
|
+
count = 0
|
54
|
+
groups.each { count += 1}
|
55
|
+
expect(count).to eq 2
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
describe ParseFiles do
|
2
|
+
|
3
|
+
let(:service_list) { ParseFiles.parse_services_file(SERVICES) }
|
4
|
+
let(:services) { Services.new }
|
5
|
+
let(:groups) { Groups.new }
|
6
|
+
|
7
|
+
describe '.parse_services_file' do
|
8
|
+
context "valid services file" do
|
9
|
+
it "should return an array with fourteen elements" do
|
10
|
+
expect(service_list.size).to eq 14
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should contain something" do
|
14
|
+
fields = service_list[10]
|
15
|
+
expect(fields[0]).to eq '0353392988'
|
16
|
+
expect(fields[1]).to eq 'Unknown'
|
17
|
+
expect(fields[2]).to start_with '15 Violet Grove'
|
18
|
+
expect(fields[3]).to be nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "empty services file" do
|
23
|
+
it "should return an empty array" do
|
24
|
+
expect(ParseFiles.parse_services_file(EMPTY)).to be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "invalid services file" do
|
29
|
+
it "should return an empty array" do
|
30
|
+
expect(ParseFiles.parse_services_file(INVALID)).to be_empty
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "missing services file" do
|
35
|
+
it "should throw an exception" do
|
36
|
+
expect { ParseFiles.parse_services_file(MISSING) }.to raise_error IOError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".map_services" do
|
42
|
+
before :each do
|
43
|
+
ParseFiles.map_services(groups,services,service_list)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create 3 groups" do
|
47
|
+
expect(groups.size).to eq 3
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create 14 services" do
|
51
|
+
expect(services.size).to eq 14
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".parse_bill_file" do
|
56
|
+
let(:call_type) { CallType.new }
|
57
|
+
|
58
|
+
before :each do
|
59
|
+
call_type.load(CALL_TYPES)
|
60
|
+
@invoice_date = ParseFiles.parse_bill_file(services,call_type,BILLS)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns invoice date" do
|
64
|
+
expect(@invoice_date).to eq '20130619'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "collates services" do
|
68
|
+
service = services.service('0418133125')
|
69
|
+
expect(service.service_summaries.size).to eq 8
|
70
|
+
expect(service.call_details.size).to eq 147
|
71
|
+
end
|
72
|
+
|
73
|
+
context "missing bill file" do
|
74
|
+
it "should throw an exception" do
|
75
|
+
expect { ParseFiles.parse_bill_file(services,call_type,MISSING) }.to raise_error IOError
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "invalid bill file" do
|
80
|
+
it "should throw an exception" do
|
81
|
+
expect { ParseFiles.parse_bill_file(services,call_type,INVALID) }.to raise_error ArgumentError
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
LOG_FILE = '/tmp/tbrlogfile'
|
4
|
+
PDF_DIR = '/tmp/201306'
|
5
|
+
|
6
|
+
describe Tbr::Processor do
|
7
|
+
|
8
|
+
let(:tbr) { Tbr::Processor.new }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
FileUtils.rm_f(LOG_FILE)
|
12
|
+
Tbr.log = Logger.new(LOG_FILE)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "should set logo to default" do
|
17
|
+
expect(tbr.logo).to include 'lib/tbr/../logo.jpg'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set replace to false" do
|
21
|
+
expect(tbr.replace).to be_falsy
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set services to an empty array" do
|
25
|
+
expect(tbr.services).to eq []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".import_services" do
|
30
|
+
it "should import data in tbr.services" do
|
31
|
+
tbr.import_services(SERVICES)
|
32
|
+
expect(tbr.services.count).to eq 14
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".logo=" do
|
37
|
+
it "should use default logo if argument is nil" do
|
38
|
+
tbr.logo = nil
|
39
|
+
expect(tbr.logo).to end_with 'lib/tbr/../logo.jpg'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should use a logo with a valid path" do
|
43
|
+
tbr.logo = './spec/data/test_logo.jpg'
|
44
|
+
expect(tbr.logo).to eq './spec/data/test_logo.jpg'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should use default logo if path is invalid and write log entry" do
|
48
|
+
tbr.logo = './spec/data/missing_logo.jpg'
|
49
|
+
expect(tbr.logo).to end_with 'lib/tbr/../logo.jpg'
|
50
|
+
expect(check_log('could not be found')).to be_truthy
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".output=" do
|
55
|
+
it "should output to /tmp if argument is nil" do
|
56
|
+
tbr.output = nil
|
57
|
+
expect(tbr.output).to eq '/tmp'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should output to supplied directory if directory exists" do
|
61
|
+
tbr.output = OUT_DIR
|
62
|
+
expect(tbr.output).to eq OUT_DIR
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should output to /tmp if output directory doesn't exist" do
|
66
|
+
tbr.output = "#{OUT_DIR}/missing"
|
67
|
+
expect(tbr.output).to eq '/tmp'
|
68
|
+
expect(check_log('No output directory')).to be_truthy
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".services=" do
|
73
|
+
it "should set services to a valid array" do
|
74
|
+
tbr.services = [1,2,3]
|
75
|
+
expect(tbr.services).to eq [1,2,3]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise an ArgumentError when service isn't an array" do
|
79
|
+
expect { tbr.services = 'error' }.to raise_error ArgumentError
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ".process" do
|
84
|
+
it "raises an ArgumentError if argument is not a string" do
|
85
|
+
expect { tbr.process(nil) }.to raise_error ArgumentError
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises an IOError if input file not found" do
|
89
|
+
expect { tbr.process(MISSING) }.to raise_error IOError
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".process - writing output", pdf: true do
|
94
|
+
before :each do
|
95
|
+
FileUtils.rm_rf(PDF_DIR)
|
96
|
+
tbr.output = '/tmp'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "writes to output if directory is valid" do
|
100
|
+
tbr.process(BILLS)
|
101
|
+
expect(Dir.exist?(PDF_DIR)).to be_truthy
|
102
|
+
expect(Dir.glob("#{PDF_DIR}/summaries/*").count).to eq 1
|
103
|
+
expect(Dir.glob("#{PDF_DIR}/details/*").count).to eq 16
|
104
|
+
expect(check_log('Empty services list')).to be_truthy
|
105
|
+
expect(check_log('completed')).to be_truthy
|
106
|
+
end
|
107
|
+
|
108
|
+
it "creates summaries" do
|
109
|
+
tbr.services = [['0353319583','Adrian','105 Dana Street','103']]
|
110
|
+
tbr.process(BILLS)
|
111
|
+
expect(Dir.glob("#{PDF_DIR}/summaries/*").count).to eq 2
|
112
|
+
expect(check_log('Empty services list')).to be_falsy
|
113
|
+
expect(check_log('completed')).to be_truthy
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def check_log(sub)
|
120
|
+
begin
|
121
|
+
File.open(LOG_FILE).each do |line|
|
122
|
+
return true if line.include?(sub)
|
123
|
+
end
|
124
|
+
return false
|
125
|
+
rescue Errno::ENOENT
|
126
|
+
return false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Service do
|
4
|
+
|
5
|
+
let(:service) { Service.new(TEST_PHONE,'Brian Collins','1000') }
|
6
|
+
let(:call_type) { CallType.new }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
call_type.load(CALL_TYPES)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".initialize" do
|
13
|
+
it "should set service_summaries to empty array" do
|
14
|
+
expect(service.service_summaries).to eq []
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set call_details to empty array" do
|
18
|
+
expect(service.call_details).to eq []
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a zero total" do
|
22
|
+
expect(service.total).to eq 0.0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#service_number" do
|
27
|
+
it "should initialise service_number" do
|
28
|
+
expect(service.service_number).to eq TEST_PHONE
|
29
|
+
end
|
30
|
+
|
31
|
+
it "shouldn't set service_number" do
|
32
|
+
expect { service.service_number = '1234' }.to raise_error NoMethodError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#name" do
|
37
|
+
it "should initialise name" do
|
38
|
+
expect(service.name).to eq 'Brian Collins'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set provided name" do
|
42
|
+
service.name = 'New Name'
|
43
|
+
expect(service.name).to eq 'New Name'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set default name" do
|
47
|
+
service.name = nil
|
48
|
+
expect(service.name).to eq 'Unassigned'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#cost_centre" do
|
53
|
+
it "should initialise cost_centre" do
|
54
|
+
expect(service.cost_centre).to eq '1000'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set provided cost_centre" do
|
58
|
+
service.cost_centre = '1234'
|
59
|
+
expect(service.cost_centre).to eq '1234'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set default cost_centre" do
|
63
|
+
service.cost_centre = nil
|
64
|
+
expect(service.cost_centre).to eq ''
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#add_service_summary" do
|
69
|
+
it "should add a service" do
|
70
|
+
service.add_service_summary(nil)
|
71
|
+
expect(service.service_summaries.size).to eq 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#add_call_detail" do
|
76
|
+
it "should add a call_detail" do
|
77
|
+
service.add_call_detail(nil)
|
78
|
+
expect(service.call_details.size).to eq 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#total" do
|
83
|
+
it "returns a total" do
|
84
|
+
service_summary = double('ServiceSummary', cost: 12.34)
|
85
|
+
service.add_service_summary(service_summary)
|
86
|
+
expect(service.total).to eq 12.34
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#service_number_format" do
|
91
|
+
context "phone number" do
|
92
|
+
it "should format as phone number" do
|
93
|
+
expect(service.service_number_format).to eq "04 1850 1461"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "non-phone service" do
|
98
|
+
it "shouldn't format the service number" do
|
99
|
+
expect(Service.new('TEST',nil,nil).service_number_format).to eq 'TEST'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|