sps_bill 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,169 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpsBill::BillCollection do
4
+
5
+ describe "##load" do
6
+ let(:bills) { SpsBill::BillCollection.load(path_spec) }
7
+ subject { bills }
8
+
9
+ context "when path spec provided" do
10
+ let(:path_spec) { '*.pdf' }
11
+ let(:mock_collection) { ['a.pdf','b.pdf'] }
12
+ before do
13
+ Dir.stub(:[]).and_return(mock_collection)
14
+ SpsBill::Bill.any_instance.stub(:do_complete_parse).and_return(nil)
15
+ end
16
+ it { should be_a(SpsBill::BillCollection) }
17
+ its(:size) { should eql(2) }
18
+
19
+ describe "#first" do
20
+ subject { bills.first }
21
+ it { should be_a(SpsBill::Bill) }
22
+ its(:source_file) { should eql('a.pdf') }
23
+ end
24
+ describe "#last" do
25
+ subject { bills.last }
26
+ it { should be_a(SpsBill::Bill) }
27
+ its(:source_file) { should eql('b.pdf') }
28
+ end
29
+ end
30
+
31
+ context "when file array provided" do
32
+ let(:path_spec) { ['a.pdf','b.pdf'] }
33
+ before do
34
+ SpsBill::Bill.any_instance.stub(:do_complete_parse).and_return(nil)
35
+ end
36
+ it { should be_a(SpsBill::BillCollection) }
37
+ its(:size) { should eql(2) }
38
+
39
+ describe "#first" do
40
+ subject { bills.first }
41
+ it { should be_a(SpsBill::Bill) }
42
+ its(:source_file) { should eql('a.pdf') }
43
+ end
44
+ describe "#last" do
45
+ subject { bills.last }
46
+ it { should be_a(SpsBill::Bill) }
47
+ its(:source_file) { should eql('b.pdf') }
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "#headers" do
53
+ {
54
+ :total_amounts => ['invoice_month','amount'],
55
+ :electricity_usages => ['invoice_month','kwh','rate','amount'],
56
+ :gas_usages => ['invoice_month','kwh','rate','amount'],
57
+ :water_usages => ['invoice_month','cubic_m','rate','amount'],
58
+ :all_data => ['invoice_month','measure','kwh','cubic_m','rate','amount'],
59
+ :unknown => nil
60
+ }.each do |dataset_selector,expected|
61
+ context "with #{dataset_selector} selector" do
62
+ subject { SpsBill::BillCollection.new.headers(dataset_selector) }
63
+ it { should eql(expected) }
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#total_amounts" do
69
+ let(:bill_a) { SpsBill::Bill.new(nil) }
70
+ let(:bill_b) { SpsBill::Bill.new(nil) }
71
+ let(:bills) { SpsBill::BillCollection.new }
72
+ before do
73
+ bill_a.instance_variable_set(:@invoice_month, Date.parse('2012-02-01'))
74
+ bill_a.instance_variable_set(:@total_amount, 111.12)
75
+ bill_b.instance_variable_set(:@invoice_month, Date.parse('2012-03-01'))
76
+ bill_b.instance_variable_set(:@total_amount, 222.23)
77
+ bills << bill_a
78
+ bills << bill_b
79
+ end
80
+ subject { bills.total_amounts(style) }
81
+ context "with solo style" do
82
+ let(:style) { :solo }
83
+ let(:expected) { [['2012-02-01',111.12],['2012-03-01',222.23]] }
84
+ it { should eql(expected)}
85
+ end
86
+ context "with all style" do
87
+ let(:style) { :all }
88
+ let(:expected) { [['2012-02-01','total_charges',nil,nil,nil,111.12],['2012-03-01','total_charges',nil,nil,nil,222.23]] }
89
+ it { should eql(expected)}
90
+ end
91
+ end
92
+
93
+ describe "#electricity_usages" do
94
+ let(:bill_a) { SpsBill::Bill.new(nil) }
95
+ let(:bill_b) { SpsBill::Bill.new(nil) }
96
+ let(:bills) { SpsBill::BillCollection.new }
97
+ before do
98
+ bill_a.instance_variable_set(:@invoice_month, Date.parse('2012-02-01'))
99
+ bill_a.instance_variable_set(:@electricity_usage, [{ kwh: 12.0, rate: 0.1234, amount: 12.34 }] )
100
+ bill_b.instance_variable_set(:@invoice_month, Date.parse('2012-03-01'))
101
+ bill_b.instance_variable_set(:@electricity_usage, [{ kwh: 24.0, rate: 0.5678, amount: 56.78 }])
102
+ bills << bill_a
103
+ bills << bill_b
104
+ end
105
+ subject { bills.electricity_usages(style) }
106
+ context "with solo style" do
107
+ let(:style) { :solo }
108
+ let(:expected) { [['2012-02-01', 12.0, 0.1234, 12.34],['2012-03-01', 24.0, 0.5678, 56.78]] }
109
+ it { should eql(expected)}
110
+ end
111
+ context "with all style" do
112
+ let(:style) { :all }
113
+ let(:expected) { [['2012-02-01', 'electricity', 12.0, nil, 0.1234, 12.34],['2012-03-01', 'electricity', 24.0, nil, 0.5678, 56.78]] }
114
+ it { should eql(expected)}
115
+ end
116
+ end
117
+
118
+
119
+ describe "#gas_usages" do
120
+ let(:bill_a) { SpsBill::Bill.new(nil) }
121
+ let(:bill_b) { SpsBill::Bill.new(nil) }
122
+ let(:bills) { SpsBill::BillCollection.new }
123
+ before do
124
+ bill_a.instance_variable_set(:@invoice_month, Date.parse('2012-02-01'))
125
+ bill_a.instance_variable_set(:@gas_usage, [{ kwh: 12.0, rate: 0.1234, amount: 12.34 }] )
126
+ bill_b.instance_variable_set(:@invoice_month, Date.parse('2012-03-01'))
127
+ bill_b.instance_variable_set(:@gas_usage, [{ kwh: 24.0, rate: 0.5678, amount: 56.78 }])
128
+ bills << bill_a
129
+ bills << bill_b
130
+ end
131
+ subject { bills.gas_usages(style) }
132
+ context "with solo style" do
133
+ let(:style) { :solo }
134
+ let(:expected) { [['2012-02-01', 12.0, 0.1234, 12.34],['2012-03-01', 24.0, 0.5678, 56.78]] }
135
+ it { should eql(expected)}
136
+ end
137
+ context "with all style" do
138
+ let(:style) { :all }
139
+ let(:expected) { [['2012-02-01', 'gas', 12.0, nil, 0.1234, 12.34],['2012-03-01', 'gas', 24.0, nil, 0.5678, 56.78]] }
140
+ it { should eql(expected)}
141
+ end
142
+ end
143
+
144
+ describe "#water_usages" do
145
+ let(:bill_a) { SpsBill::Bill.new(nil) }
146
+ let(:bill_b) { SpsBill::Bill.new(nil) }
147
+ let(:bills) { SpsBill::BillCollection.new }
148
+ before do
149
+ bill_a.instance_variable_set(:@invoice_month, Date.parse('2012-02-01'))
150
+ bill_a.instance_variable_set(:@water_usage, [{ cubic_m: 12.0, rate: 0.1234, amount: 12.34 }] )
151
+ bill_b.instance_variable_set(:@invoice_month, Date.parse('2012-03-01'))
152
+ bill_b.instance_variable_set(:@water_usage, [{ cubic_m: 24.0, rate: 0.5678, amount: 56.78 }])
153
+ bills << bill_a
154
+ bills << bill_b
155
+ end
156
+ subject { bills.water_usages(style) }
157
+ context "with solo style" do
158
+ let(:style) { :solo }
159
+ let(:expected) { [['2012-02-01', 12.0, 0.1234, 12.34],['2012-03-01', 24.0, 0.5678, 56.78]] }
160
+ it { should eql(expected)}
161
+ end
162
+ context "with all style" do
163
+ let(:style) { :all }
164
+ let(:expected) { [['2012-02-01', 'water', nil, 12.0, 0.1234, 12.34],['2012-03-01', 'water', nil, 24.0, 0.5678, 56.78]] }
165
+ it { should eql(expected)}
166
+ end
167
+ end
168
+
169
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpsBill::Bill do
4
+
5
+ let(:bill) { SpsBill::Bill.new(nil) }
6
+ subject { bill }
7
+
8
+ describe "##new" do
9
+ it { should be_a(SpsBill::Bill) }
10
+ end
11
+
12
+ [
13
+ :source_file,:reader,
14
+ :account_number,:total_amount,:invoice_date,:invoice_month,
15
+ :electricity_usage,:gas_usage,:water_usage
16
+ ].each do |supported_attribute|
17
+ describe "##{supported_attribute}" do
18
+ it { should respond_to(supported_attribute) }
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ include PdfSamplesHelper
3
+
4
+ describe PDF::Reader::ObjectHash do
5
+
6
+ context "when there is a junk prefix" do
7
+ let(:sample_name) { junk_prefix_pdf_sample_name }
8
+ let(:object_hash) { PDF::Reader::ObjectHash.new(sample_name) }
9
+ let(:stream) { object_hash.instance_variable_get(:@io) }
10
+ before { stream.rewind }
11
+ subject { stream.read(4) }
12
+ it { should eql("%PDF") }
13
+ end
14
+
15
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'getoptions'
3
+
4
+ describe SpsBill::Shell do
5
+
6
+ describe "##usage" do
7
+ subject { SpsBill::Shell.usage }
8
+ it "should print help" do
9
+ STDOUT.should_receive(:puts)
10
+ subject
11
+ end
12
+ end
13
+
14
+ describe "with help parameter" do
15
+ let(:options) { GetOptions.new(SpsBill::Shell::OPTIONS, ['-h']) }
16
+ let(:shell) { SpsBill::Shell.new(options) }
17
+ subject { shell.options[:help] }
18
+ it { should be_true }
19
+ describe "#run" do
20
+ subject { shell.run }
21
+ it "should print usage" do
22
+ SpsBill::Shell.should_receive(:usage)
23
+ subject
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "with raw parameter" do
29
+ let(:options) { GetOptions.new(SpsBill::Shell::OPTIONS, ['-r']) }
30
+ let(:shell) { SpsBill::Shell.new(options) }
31
+ subject { shell.options[:raw] }
32
+ it { should be_true }
33
+ describe "#format_header" do
34
+ let(:data) { ['some','data'] }
35
+ subject { shell.format_header(data) }
36
+ it { should be_nil }
37
+ end
38
+ end
39
+
40
+ {
41
+ 'all' => :all_data,
42
+ 'charges' => :total_amounts,
43
+ 'electricity' => :electricity_usages,
44
+ 'gas' => :gas_usages,
45
+ 'water' => :water_usages
46
+ }.each do |data,expected_method|
47
+ describe "with data=#{data} parameter" do
48
+ let(:options) { GetOptions.new(SpsBill::Shell::OPTIONS, ['-d',data]) }
49
+ let(:shell) { SpsBill::Shell.new(options) }
50
+ subject { shell.options[:data] }
51
+ it { should eql(data) }
52
+ describe "#run" do
53
+ subject { shell.run }
54
+ it "should export #{expected_method}" do
55
+ shell.should_receive(:export).with(expected_method)
56
+ subject
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
data/sps_bill.gemspec ADDED
@@ -0,0 +1,100 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sps_bill"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Gallagher"]
12
+ s.date = "2012-07-20"
13
+ s.description = "a library that can read SP Services PDF bills and extract and summarize the bill details"
14
+ s.email = "gallagher.paul@gmail.com"
15
+ s.executables = ["sps_bill"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ ".rvmrc",
24
+ ".travis.yml",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "Guardfile",
28
+ "LICENSE",
29
+ "README.rdoc",
30
+ "Rakefile",
31
+ "bin/sps_bill",
32
+ "lib/pdf/object_hash.rb",
33
+ "lib/pdf/positional_text_receiver.rb",
34
+ "lib/pdf/structured_reader.rb",
35
+ "lib/pdf/textangle.rb",
36
+ "lib/sps_bill.rb",
37
+ "lib/sps_bill/bill.rb",
38
+ "lib/sps_bill/bill_collection.rb",
39
+ "lib/sps_bill/bill_parser.rb",
40
+ "lib/sps_bill/shell.rb",
41
+ "lib/sps_bill/version.rb",
42
+ "scripts/data/.gitkeep",
43
+ "scripts/scan_all_bills.sh",
44
+ "spec/fixtures/pdf_samples/.gitkeep",
45
+ "spec/fixtures/pdf_samples/junk_prefix.pdf",
46
+ "spec/fixtures/personal_pdf_samples/.gitkeep",
47
+ "spec/fixtures/personal_pdf_samples/expectations.yml.sample",
48
+ "spec/integration/personal_samples_spec.rb",
49
+ "spec/spec_helper.rb",
50
+ "spec/support/bill_examples.rb",
51
+ "spec/support/pdf_samples_helper.rb",
52
+ "spec/unit/bill_collection_spec.rb",
53
+ "spec/unit/bill_spec.rb",
54
+ "spec/unit/pdf/object_hash_spec.rb",
55
+ "spec/unit/shell_spec.rb",
56
+ "sps_bill.gemspec"
57
+ ]
58
+ s.homepage = "https://github.com/tardate/sps_bill_scanner"
59
+ s.licenses = ["MIT"]
60
+ s.require_paths = ["lib"]
61
+ s.rubygems_version = "1.8.15"
62
+ s.summary = "SP Services PDF bill structured data reader"
63
+
64
+ if s.respond_to? :specification_version then
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<pdf-reader>, ["= 1.1.1"])
69
+ s.add_runtime_dependency(%q<getoptions>, ["~> 0.3"])
70
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
72
+ s.add_development_dependency(%q<rcov>, [">= 0"])
73
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2.2"])
74
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
75
+ s.add_development_dependency(%q<rdoc>, ["~> 3.11"])
76
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<pdf-reader>, ["= 1.1.1"])
79
+ s.add_dependency(%q<getoptions>, ["~> 0.3"])
80
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
82
+ s.add_dependency(%q<rcov>, [">= 0"])
83
+ s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
84
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
85
+ s.add_dependency(%q<rdoc>, ["~> 3.11"])
86
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<pdf-reader>, ["= 1.1.1"])
90
+ s.add_dependency(%q<getoptions>, ["~> 0.3"])
91
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
93
+ s.add_dependency(%q<rcov>, [">= 0"])
94
+ s.add_dependency(%q<rake>, ["~> 0.9.2.2"])
95
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
96
+ s.add_dependency(%q<rdoc>, ["~> 3.11"])
97
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
98
+ end
99
+ end
100
+
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sps_bill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Gallagher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pdf-reader
16
+ requirement: &70313136422520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70313136422520
25
+ - !ruby/object:Gem::Dependency
26
+ name: getoptions
27
+ requirement: &70313136421900 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.3'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70313136421900
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70313136421060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70313136421060
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70313136420480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70313136420480
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70313136419920 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70313136419920
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70313136419140 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.2.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70313136419140
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70313136418160 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 2.8.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70313136418160
91
+ - !ruby/object:Gem::Dependency
92
+ name: rdoc
93
+ requirement: &70313136417580 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '3.11'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70313136417580
102
+ - !ruby/object:Gem::Dependency
103
+ name: guard-rspec
104
+ requirement: &70313136417060 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70313136417060
113
+ description: a library that can read SP Services PDF bills and extract and summarize
114
+ the bill details
115
+ email: gallagher.paul@gmail.com
116
+ executables:
117
+ - sps_bill
118
+ extensions: []
119
+ extra_rdoc_files:
120
+ - LICENSE
121
+ - README.rdoc
122
+ files:
123
+ - .document
124
+ - .rspec
125
+ - .rvmrc
126
+ - .travis.yml
127
+ - Gemfile
128
+ - Gemfile.lock
129
+ - Guardfile
130
+ - LICENSE
131
+ - README.rdoc
132
+ - Rakefile
133
+ - bin/sps_bill
134
+ - lib/pdf/object_hash.rb
135
+ - lib/pdf/positional_text_receiver.rb
136
+ - lib/pdf/structured_reader.rb
137
+ - lib/pdf/textangle.rb
138
+ - lib/sps_bill.rb
139
+ - lib/sps_bill/bill.rb
140
+ - lib/sps_bill/bill_collection.rb
141
+ - lib/sps_bill/bill_parser.rb
142
+ - lib/sps_bill/shell.rb
143
+ - lib/sps_bill/version.rb
144
+ - scripts/data/.gitkeep
145
+ - scripts/scan_all_bills.sh
146
+ - spec/fixtures/pdf_samples/.gitkeep
147
+ - spec/fixtures/pdf_samples/junk_prefix.pdf
148
+ - spec/fixtures/personal_pdf_samples/.gitkeep
149
+ - spec/fixtures/personal_pdf_samples/expectations.yml.sample
150
+ - spec/integration/personal_samples_spec.rb
151
+ - spec/spec_helper.rb
152
+ - spec/support/bill_examples.rb
153
+ - spec/support/pdf_samples_helper.rb
154
+ - spec/unit/bill_collection_spec.rb
155
+ - spec/unit/bill_spec.rb
156
+ - spec/unit/pdf/object_hash_spec.rb
157
+ - spec/unit/shell_spec.rb
158
+ - sps_bill.gemspec
159
+ homepage: https://github.com/tardate/sps_bill_scanner
160
+ licenses:
161
+ - MIT
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.15
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: SP Services PDF bill structured data reader
184
+ test_files: []