diamond_invoice 0.5.1
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.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +57 -0
- data/Rakefile +8 -0
- data/data/diamond_invoice.txt +170 -0
- data/diamond_invoice.gemspec +25 -0
- data/lib/diamond_invoice.rb +52 -0
- data/lib/diamond_invoice/version.rb +3 -0
- data/spec/diamond_invoice_spec.rb +34 -0
- metadata +69 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jon Canady
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# DiamondInvoice
|
2
|
+
|
3
|
+
Does some trivial parsing of the email invoice format used by [Diamond Comic
|
4
|
+
Distributors](http://www.diamondcomics.com/).
|
5
|
+
|
6
|
+
## Dedication
|
7
|
+
|
8
|
+
Adapted from some really old PHP code I wrote really early in my career for
|
9
|
+
[Comic Town](http://comictown.net) in Columbus, OH. If you're ever in Columbus
|
10
|
+
and need comics, give them a visit.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
gem install diamond_invoice
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
First, create a new DiamondInvoice and give it your emailed invoice, as a
|
19
|
+
string.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@invoice = DiamondInvoice.new(File.read('path_to_invoice.txt'))
|
23
|
+
```
|
24
|
+
|
25
|
+
Fetch a list of incoming items as an all-lowercase array.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
@invoice.new_titles
|
29
|
+
|
30
|
+
# => ["amazing spider-man #62", "animal man #2", ... ]
|
31
|
+
```
|
32
|
+
|
33
|
+
Got some books you don't want to see in the list? Ignore them like so:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Ignore any title that contains "addult supplement."
|
37
|
+
# Case insensitive, matches if the keyword apepars anywhere in the title.
|
38
|
+
@invoice.excluded_titles << "adult supplement"
|
39
|
+
```
|
40
|
+
|
41
|
+
## Testing
|
42
|
+
|
43
|
+
$ rake
|
44
|
+
|
45
|
+
Requires rspec ~> 2.7
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create a branch (`git checkout -b my_feature_or_bugfix`)
|
51
|
+
3. Commit your changes (`git commit -am "Description of my change."`)
|
52
|
+
4. Push to your branch (`git push origin my_feature_or_bugfix`)
|
53
|
+
5. Send a [pull request](http://help.github.com/send-pull-requests/)
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
See the `LICENSE` file.
|
data/Rakefile
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
O R D E R S T A T U S R E P O R T 111212-23202459
|
2
|
+
|
3
|
+
ACCOUNT# 25582 COMIC TOWN III GROUP CODE P020
|
4
|
+
Please call : 1-800-45-COMIC or FAX : (800)329-2878 for all customer service and reorders.
|
5
|
+
YOUR CUSTOMER SERVICE REP IS STEPHANIE ,Ext. 825
|
6
|
+
DC CO-OP SUMMARY:
|
7
|
+
BEGINNING BALANCE AS OF 12/01/11: 2,701.73
|
8
|
+
EARNED : 190.05
|
9
|
+
USED : 0.00
|
10
|
+
EXPIRED: 273.79
|
11
|
+
ENDING BALANCE AS OF 12/09/11: 2,617.99
|
12
|
+
|
13
|
+
THE FOLLOWING ITEMS WERE ORDERED OR CANCELLED SINCE YOU RECEIVED YOUR LAST INVOICE:
|
14
|
+
ORDER REDUCTION TOTAL QTY ITEMCODE TITLE
|
15
|
+
DUE DATE ON ORDER
|
16
|
+
|
17
|
+
ORDER STATUS: THE FOLLOWING ITEMS ARE ELIGIBLE FOR ORDER REDUCTIONS
|
18
|
+
DUE TO VENDOR LATE SHIPPING, MIS-SOLICITAION, OR ORDERS MATCHED TO A PREVIOUS SOLICITATION.
|
19
|
+
12/19/11 2 AUG100789 E FATHOM BLUE DESCENT #4 CVR A ALEX SANCHEZ 2.9900
|
20
|
+
12/19/11 2 AUG100790 E FATHOM BLUE DESCENT #4 CVR B SCOTT CLARK 2.9900
|
21
|
+
|
22
|
+
|
23
|
+
ORDER NO QTY ORDERED ITEMCODE CODE TITLE PRICE
|
24
|
+
ORDER STATUS: UNCONFIRMED ORDER
|
25
|
+
54246434 1 SEP110548 D RED SKULL #5 (OF 5) 2.9900
|
26
|
+
|
27
|
+
|
28
|
+
ORDER STATUS: CANCELLED INITIAL ORDER
|
29
|
+
53988153 3- JUN110486 D 04 MORNING GLORIES YEARBOOK 2011 2.9900
|
30
|
+
54140000 1- SEP110786 E 02 HAUNTED CITY #3 CVR A RYAN 3.5000
|
31
|
+
54230910 1- NOV110594 D 04 BRILLIANT #4 MACK VAR (MR) (OF 5) 3.9500
|
32
|
+
54230910 1- NOV110595 D 04 BRILLIANT #4 OEMING VAR (MR) (OF 5) 3.9500
|
33
|
+
54230910 1- NOV111048 F 02 HONEY WEST #6 (C: 0-1-0) 3.9900
|
34
|
+
|
35
|
+
|
36
|
+
ORDER STATUS: CANCELLED ORDER INCREASE
|
37
|
+
54243583 1- OCT118104 D 04 PUNISHERMAX #17 2ND PTG DILLON VAR (MR) (PP #998) 3.9900
|
38
|
+
54243583 1- OCT118105 D 04 PUNISHERMAX #18 2ND PTG DILLON VAR (MR) (PP #998) 3.9900
|
39
|
+
|
40
|
+
|
41
|
+
ORDER STATUS: FREE ORDER INCREASE
|
42
|
+
54245613 1 NOV110837 F PEANUTS #1 (OF 4) 3.9900
|
43
|
+
54250303 1 OCT110920 F IRREDEEMABLE #1 ARTIST EDITION 3.9900
|
44
|
+
|
45
|
+
NEW PRODUCT ON THIS INVOICE IS FOR AN ON SALE DATE OF WEDNESDAY, 12/21/11
|
46
|
+
C U S T O M E R I N V O I C E 111212-23202459
|
47
|
+
ACCOUNT# 25582 COMIC TOWN III GROUP CODE P020 DATE 12/12/11
|
48
|
+
REORDER TYPE(T) 2 = IN STOCK DIRECT SHIP 3 = ORDER INC 4 = ADVANCE 5 = B/O 6 = CREDIT 7 = INSTOCK RESHIP 9 = SPECIAL PROGRAM
|
49
|
+
P = PREPACK # = ORDER WAS PARTIALLY FILLED
|
50
|
+
UNITS ORDER UNIT UNIT INVOICE INV
|
51
|
+
SHIPPED NUMBER T ITEMCODE TITLE RETAIL DISC COST AMOUNT REF
|
52
|
+
1 00000000 OCT108124 DAY EARLY DELIVERY COMPLIANCE FUND (NET) 0.00 0.0 4.0000 4.00
|
53
|
+
63 54186319 OCT110631D AMAZING SPIDER-MAN #676 3.99 55.0 1.7955 113.12 Marvel
|
54
|
+
3 54244989 P AUG110212D ANIMAL MAN #2 2.99 55.0 1.3455 4.04 DC
|
55
|
+
12 54090854 AUG110680D ANITA BLAKE CIRCUS DAMNED SCOUNDREL #3 (OF 5) (MR) 3.99 55.0 1.7955 21.55 Marvel
|
56
|
+
1 54186319 OCT110809E ARCHIE & FRIENDS #159 2.99 50.0 1.4950 1.50
|
57
|
+
85 54186319 OCT110597D AVENGERS #20 3.99 55.0 1.7955 152.62 Marvel
|
58
|
+
1 54140000 SEP111349H BACK ISSUE #53 (C: 0-1-1) 8.95 40.0 5.3700 5.37
|
59
|
+
1 54090854 AUG110039V BALTIMORE VOL 01 THE PLAGUE SHIPS TP (C: 0-1-2) 18.99 52.5 9.0203 9.02 Drk Hrs
|
60
|
+
5 54244989 P AUG118063D BATMAN #1 2ND PTG 2.99 55.0 1.3455 6.73 DC
|
61
|
+
2.99 55.0 1.3455 13.46 DC
|
62
|
+
2,179 TOTAL UNITS SHIPPED TOTAL COST: 3,506.68
|
63
|
+
CREDIT SECTION
|
64
|
+
1- 54233356 6 SEP110548D RED SKULL #5 (OF 5) 0.00 55.0 1.3455 1.35- Marvel
|
65
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
66
|
+
SHORTAGE CREDIT
|
67
|
+
2 54186319 OCT110015D THE STRAIN #1 (OF 11) MORRIS VAR CVR 3.50 12.5 1.1250- 2.25- Drk Hrs
|
68
|
+
PRICE ADJUSTMENT
|
69
|
+
1- 54233356 6 SEP110522D ULTIMATE COMICS ULTIMATES #4 0.00 55.0 1.7955 1.80- Marvel
|
70
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
71
|
+
SHORTAGE CREDIT
|
72
|
+
2- 54186319 0 OCT110575D WALKING DEAD WEEKLY #49 (MR) 2.99 55.0 1.3455 2.69- Image
|
73
|
+
SHORTAGE CREDIT
|
74
|
+
|
75
|
+
ACCOUNT: 25582 C U S T O M E R I N V O I C E 111212-23202459
|
76
|
+
20- 54186319 0 OCT110675D X-MEN #22 XREGB 3.99 55.0 1.7955 35.91- Marvel
|
77
|
+
SHORTAGE CREDIT
|
78
|
+
2- 54233356 6 SEP110604D X-MEN LEGACY #259 XREGG 2.99 55.0 1.3455 2.69- Marvel
|
79
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
80
|
+
SHORTAGE CREDIT
|
81
|
+
TOTAL UNITS SHIPPED TOTAL COST: 46.69-
|
82
|
+
DEBIT SECTION
|
83
|
+
25 54140000 SEP110615D WOLVERINE BEST THERE IS #12 2.99 88.7 0.4500 11.25 Marvel
|
84
|
+
PRICE ADJUSTMENT
|
85
|
+
TOTAL UNITS SHIPPED TOTAL COST: 11.25
|
86
|
+
DIRECT SHIP SECTION
|
87
|
+
0 00000000 D 0.00 0.0 0.0000 0.00
|
88
|
+
1 54246998 2 JUN110380E ANNE RICE SERVANT OF THE BONES #1 (OF 6) 3.99 47.0 2.1147 2.11 IDW
|
89
|
+
1 54246998 2 AUG050185D ARKHAM ASYLUM ANNIVERSARY ED SC (MR) 17.99 55.0 8.0955 8.10 DC
|
90
|
+
1 54246998 2 JUN110266D BATMAN ARKHAM CITY HC 22.99 55.0 10.3455 10.35 DC
|
91
|
+
1 54246998 2 DEC058055D BATMAN DARK KNIGHT RETURNS TP 14.99 55.0 6.7455 6.75 DC
|
92
|
+
2 54246998 2 JUL110245D BATMAN NOEL DELUXE EDITION HC 22.99 55.0 10.3455 20.69 DC
|
93
|
+
1 54246998 2 JUL110251D BATMAN THE LONG HALLOWEEN TP 24.99 55.0 11.2455 11.25 DC
|
94
|
+
1 54246998 2 APR110192D BLACKEST NIGHT TP 19.99 55.0 8.9955 9.00 DC
|
95
|
+
1,500 54246998 2 SUPPLY115J COMICARE CURRENT BOARDS (SOLD IN 100) (Net) PI 0.0 0.0456 68.40
|
96
|
+
1,500 54246998 2 SUPPLY105J COMICARE CURRENT PE BAGS (ORDER IN 100) (Net) PI 0.0 0.0351 52.65
|
97
|
+
100 54246998 2 SUPPLY117J COMICARE MAG BOARDS (SOLD IN 50) (Net) PI 0.0 0.0562 5.62
|
98
|
+
100 54246998 2 SUPPLY108J COMICARE MAG PE BAGS (ORDER IN 100) (Net) PI 0.0 0.0430 4.30
|
99
|
+
2 54246998 2 AUG118052D DAREDEVIL #3 2ND PTG RIVERA VAR (PP #990) 2.99 55.0 1.3455 2.69 Marvel
|
100
|
+
1 54246998 2 MAR058123D FABLES TP VOL 02 ANIMAL FARM 12.99 55.0 5.8455 5.85 DC
|
101
|
+
1 54246998 2 JAN110422D FABLES TP VOL 15 ROSE RED (MR) 17.99 55.0 8.0955 8.10 DC
|
102
|
+
1 54246998 2 FEB100185D GREEN LANTERN REBIRTH TP NEW EDITION 14.99 55.0 6.7455 6.75 DC
|
103
|
+
1 54246998 2 OCT110274D LOONEY TUNES #204 2.99 55.0 1.3455 1.35 DC
|
104
|
+
2,000 54246998 2 SUPPLY668J MYLITES 2 CURRENT (ORDER IN 50) (Net) PI 27.1 0.1400 280.00
|
105
|
+
250 54246998 2 SUPPLY677J MYLITES 2 SILVER GOLD (ORDER IN 50) (Net) PI 17.6 0.1680 42.00
|
106
|
+
1,000 54246998 2 SUPPLY678J MYLITES 2 STANDARD (ORDER IN 50) (Net) PI 26.5 0.1440 144.00
|
107
|
+
2 54246998 2 SEP118079E STAR TREK ONGOING #2 2ND PTG (PP #994) 3.99 47.0 2.1147 4.23 IDW
|
108
|
+
2 54246998 2 SEP110027D STAR WARS CRIMSON EMPIRE III EMPIRE LOST #2 (OF 6) 3.50 55.0 1.5750 3.15 Drk Hrs
|
109
|
+
2 54246998 2 MAY110017D STAR WARS DARK TIMES OUT O/T WILDERNESS #1 (OF 5) 2.99 55.0 1.3455 2.69 Drk Hrs
|
110
|
+
1 54246998 2 SEP110389D THOUGHT BUBBLE ANTHOLOGY #1 2.99 55.0 1.3455 1.35 Image
|
111
|
+
2 54246998 2 MAY110611D ULTIMATE COMICS FALLOUT #1 (OF 6) DOSM 3.99 0.0 0.0000 0.00 Marvel
|
112
|
+
2 54246998 2 MAY110611D ULTIMATE COMICS FALLOUT #1 (OF 6) DOSM 3.99 0.0 0.0000 0.00 Marvel
|
113
|
+
1 54246998 2 MAY110611D ULTIMATE COMICS FALLOUT #1 (OF 6) DOSM 3.99 0.0 0.0000 0.00 Marvel
|
114
|
+
1 54246998 2 MAY110611D ULTIMATE COMICS FALLOUT #1 (OF 6) DOSM 3.99 0.0 0.0000 0.00 Marvel
|
115
|
+
1 54246998 2 MAY110611D ULTIMATE COMICS FALLOUT #1 (OF 6) DOSM 3.99 0.0 0.0000 0.00 Marvel
|
116
|
+
2 54246998 2 JUL110605D ULTIMATE COMICS SPIDER-MAN #1 3.99 55.0 1.7955 3.59 Marvel
|
117
|
+
1 54246434 2 SEP110522D ULTIMATE COMICS ULTIMATES #4 3.99 55.0 1.7955 1.80 Marvel
|
118
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
119
|
+
1 54246998 2 JUL068351D WALKING DEAD TP VOL 01 DAYS GONE BYE 9.99 60.0 3.9960 4.00 Image
|
120
|
+
1 54246998 2 SEP088204D WALKING DEAD TP VOL 02 MILES BEHIND US (NEW PTG) 14.99 60.0 5.9960 6.00 Image
|
121
|
+
2 54246434 2 OCT110575D WALKING DEAD WEEKLY #49 (MR) 2.99 55.0 1.3455 2.69 Image
|
122
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
123
|
+
1 54246998 2 AUG111043E WALT DISNEY DONALD DUCK HC VOL 01 LOST I/T ANDES ( 24.99 47.0 13.2447 13.24
|
124
|
+
20 54246434 2 OCT110675D X-MEN #22 XREGB 3.99 55.0 1.7955 35.91 Marvel
|
125
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
126
|
+
1 54246998 2 JUN110693D X-MEN LEGACY #254 2.99 55.0 1.3455 1.35 Marvel
|
127
|
+
|
128
|
+
ACCOUNT: 25582 C U S T O M E R I N V O I C E 111212-23202459
|
129
|
+
1 54246998 2 JUL110699D X-MEN LEGACY #255 2.99 55.0 1.3455 1.35 Marvel
|
130
|
+
1 54246998 2 JUL110700D X-MEN LEGACY #256 2.99 55.0 1.3455 1.35 Marvel
|
131
|
+
2 54246434 2 SEP110604D X-MEN LEGACY #259 XREGG 2.99 55.0 1.3455 2.69 Marvel
|
132
|
+
SHORTAGE/DAMAGE REPLACEMENT
|
133
|
+
2 54246998 2 SEP110604D X-MEN LEGACY #259 XREGG 2.99 55.0 1.3455 2.69 Marvel
|
134
|
+
6,513 TOTAL UNITS SHIPPED TOTAL COST: 778.04
|
135
|
+
|
136
|
+
DIAMOND COMIC DISTRIBUTORS, INC.
|
137
|
+
Remit to: P.O.BOX 79582
|
138
|
+
BALTIMORE MD 21279-0582
|
139
|
+
W E E K L Y I N V O I C E R E C A P 111212-23202459
|
140
|
+
ACCOUNT# 25582 SHIP TO: BILL TO: DATE 12/12/11
|
141
|
+
GROUP CODE P020 COMIC TOWN III NAMTAB INC
|
142
|
+
TERMS COD CERTIFIED 1249 MORSE RD DBA COMIC TOWN III
|
143
|
+
1249 MORSE RD
|
144
|
+
COLUMBUS OH 43229 COLUMBUS OH 43229
|
145
|
+
INVOICE RETAIL INVOICE AMOUNT
|
146
|
+
Diamond Comics 878480 7,733.98 3,451.93
|
147
|
+
UPS 878480 150.62
|
148
|
+
Direct Ship Diamond Comics 878505 95.75 43.09
|
149
|
+
Direct Ship Diamond Comics 880067 1,092.61 734.95
|
150
|
+
Direct Ship Diamond Comics
|
151
|
+
Direct Ship UPS 908323 76.40
|
152
|
+
Diamond Comics 912655 42.89 19.31
|
153
|
+
___________ ___________
|
154
|
+
INVOICING TOTALS 8,965.23 4,476.30 # USD
|
155
|
+
# THIS AMOUNT IS PAYABLE C.O.D. CERTIFIED
|
156
|
+
|
157
|
+
|
158
|
+
PROMPT PAYMENT IS APPRECIATED AND WILL ENSURE RETENTION OF YOUR CURRENT PAYMENT TERMS.
|
159
|
+
COUNTRY OF EXPORT - U.S.A.
|
160
|
+
AMOUNT INVOICED BY VENDOR
|
161
|
+
RETAIL INVOICE AMOUNT
|
162
|
+
DC Comics 3,214.86 1,422.11
|
163
|
+
Image Comics 150.12 66.32
|
164
|
+
Dark Horse Comics 248.42 109.58
|
165
|
+
Marvel Comics 3,796.73 1,636.44
|
166
|
+
Please call : 1-800-45-COMIC or FAX : (800)329-2878 for all customer service and reorders.
|
167
|
+
YOUR CUSTOMER SERVICE REP IS STEPHANIE ,Ext. 825 AND YOUR SALES REP IS F. LIMCUANDO ,Ext. 329
|
168
|
+
YOUR CREDIT ANALYST IS PAULA SIMMONS ,Ext. 257
|
169
|
+
** DIAMOND COMIC DISTRIBUTORS, INC. IS A SALES AGENT WITH RESPECT TO THIS SALE.
|
170
|
+
THANK YOU FOR YOUR BUSINESS
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "diamond_invoice/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "diamond_invoice"
|
7
|
+
s.version = DiamondInvoice::VERSION
|
8
|
+
s.authors = ["Jon Canady"]
|
9
|
+
s.email = ["jon@joncanady.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Reads the Diamond Comic Distributor email invoice."
|
12
|
+
s.description = %q{Parses and extracts useful information from Diamond Comic Distributor's invoice files.}
|
13
|
+
|
14
|
+
# wtf?
|
15
|
+
s.rubyforge_project = "diamond_invoice"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# specify any dependencies here; for example:
|
23
|
+
s.add_development_dependency "rspec", "~> 2.7"
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
25
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "diamond_invoice/version"
|
2
|
+
|
3
|
+
class DiamondInvoice
|
4
|
+
|
5
|
+
attr_accessor :start_marker, :end_marker, :excluded_titles
|
6
|
+
attr_accessor :invoice, :new_titles
|
7
|
+
|
8
|
+
def initialize(invoice)
|
9
|
+
@invoice = invoice
|
10
|
+
@start_marker = /C U S T O M E R I N V O I C E/
|
11
|
+
@end_marker = /CREDIT SECTION/
|
12
|
+
@excluded_titles = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def new_titles
|
16
|
+
@new_titles ||= parse_titles
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_titles
|
20
|
+
@new_titles = []
|
21
|
+
start_section = @invoice.index(@start_marker)
|
22
|
+
end_section = @invoice.index(@end_marker)
|
23
|
+
|
24
|
+
@invoice[start_section..end_section].each_line do |line|
|
25
|
+
if item_line?(line)
|
26
|
+
title = title_from_line_item(line)
|
27
|
+
@new_titles << title unless excluded_title?(title)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@new_titles
|
32
|
+
end
|
33
|
+
|
34
|
+
# parse the title from the line item
|
35
|
+
def title_from_line_item(line)
|
36
|
+
line[31..86].strip.downcase
|
37
|
+
end
|
38
|
+
|
39
|
+
# Is this string a line item on the invoice?
|
40
|
+
# Line items have a number (qty?) in the first ten chars.
|
41
|
+
def item_line?(line)
|
42
|
+
line[0..10].to_i > 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def excluded_title?(title)
|
46
|
+
@excluded_titles.map { |pattern| title.match(pattern.downcase) }.any?
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'diamond_invoice'
|
2
|
+
|
3
|
+
describe DiamondInvoice do
|
4
|
+
|
5
|
+
# the sample file provided has nine incoming books
|
6
|
+
context "when providing a list of new books" do
|
7
|
+
|
8
|
+
subject { DiamondInvoice.new(File.read('data/diamond_invoice.txt')) }
|
9
|
+
|
10
|
+
it "provides an array of new titles" do
|
11
|
+
subject.new_titles.should == ["day early delivery compliance fund (net)",
|
12
|
+
"amazing spider-man #676",
|
13
|
+
"animal man #2",
|
14
|
+
"anita blake circus damned scoundrel #3 (of 5) (mr)",
|
15
|
+
"archie & friends #159",
|
16
|
+
"avengers #20",
|
17
|
+
"back issue #53 (c: 0-1-1)",
|
18
|
+
"baltimore vol 01 the plague ships tp (c: 0-1-2)",
|
19
|
+
"batman #1 2nd ptg"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "ignores anything in the @excluded_titles list" do
|
23
|
+
subject.excluded_titles << "avengers"
|
24
|
+
subject.new_titles.should_not include("avengers #20")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignores case when excluding titles" do
|
28
|
+
subject.excluded_titles << "AVENGERS"
|
29
|
+
subject.new_titles.should_not include("avengers #20")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diamond_invoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Canady
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70332052588160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.7'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70332052588160
|
25
|
+
description: Parses and extracts useful information from Diamond Comic Distributor's
|
26
|
+
invoice files.
|
27
|
+
email:
|
28
|
+
- jon@joncanady.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- data/diamond_invoice.txt
|
40
|
+
- diamond_invoice.gemspec
|
41
|
+
- lib/diamond_invoice.rb
|
42
|
+
- lib/diamond_invoice/version.rb
|
43
|
+
- spec/diamond_invoice_spec.rb
|
44
|
+
homepage: ''
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: diamond_invoice
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Reads the Diamond Comic Distributor email invoice.
|
68
|
+
test_files:
|
69
|
+
- spec/diamond_invoice_spec.rb
|