qif 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v1.1.0 Added block version of new method to writer and error checking on
2
+ files. [elmatou]
3
+
1
4
  v1.0 Added account types and fields from QIF specification. [elmatou]
2
5
 
3
6
  v0.5 Writes qif files without a record separator after the header. [jscipione]
data/Manifest CHANGED
@@ -1,17 +1,24 @@
1
1
  CHANGELOG
2
2
  LICENSE
3
3
  Manifest
4
+ QIF_references
5
+ README.rdoc
4
6
  Rakefile
5
7
  lib/qif.rb
6
8
  lib/qif/date_format.rb
7
9
  lib/qif/reader.rb
8
10
  lib/qif/transaction.rb
9
11
  lib/qif/writer.rb
10
- qif.gemspec
11
12
  spec/fixtures/3_records_ddmmyy.qif
12
13
  spec/fixtures/3_records_ddmmyyyy.qif
14
+ spec/fixtures/3_records_dmyy.qif
15
+ spec/fixtures/3_records_invalid_header.qif
13
16
  spec/fixtures/3_records_mmddyy.qif
14
17
  spec/fixtures/3_records_mmddyyyy.qif
18
+ spec/fixtures/3_records_separator.qif
19
+ spec/fixtures/not_a_QIF_file.txt
20
+ spec/fixtures/quicken_investment_account.qif
21
+ spec/fixtures/quicken_non_investement_account.qif
15
22
  spec/lib/date_format_spec.rb
16
23
  spec/lib/reader_spec.rb
17
24
  spec/lib/transaction_spec.rb
@@ -0,0 +1,728 @@
1
+ Have to check : http://cpansearch.perl.org/src/MMCGILLIS/Finance-QIF-2.04/lib/Finance/QIF.pm
2
+
3
+
4
+ Source : http://web.intuit.com/support/quicken/docs/d_qif.html
5
+ Quicken Interchange Format (QIF) files
6
+
7
+ The Quicken interchange format (QIF) is a specially formatted text (ASCII) file that enables Quicken transactions to be moved from one Quicken account register into another Quicken account register, or to or from other programs that support the QIF format.
8
+
9
+ Note: For Quicken to translate data from a text file into the Quicken register as transactions, the text file must be in the QIF format.
10
+
11
+ Required File Formatting
12
+
13
+ Each transaction must end with a symbol, indicating the end of entry. Each item in the transaction must display on a separate line. When Quicken exports an account register or list, it adds a line to the top of the file that identifies the type of account or list. Listed below are the header lines Quicken adds to the exported files:
14
+
15
+ Header Type of data
16
+ !Type:Bank Bank account transactions
17
+ !Type:Cash Cash account transactions
18
+ !Type:CCard Credit card account transactions
19
+ !Type:Invst Investment account transactions
20
+ !Type:Oth A Asset account transactions
21
+ !Type:Oth L Liability account transactions
22
+ !Account Account list or which account follows
23
+ !Type:Cat Category list
24
+ !Type:Class Class list
25
+ !Type:Memorized Memorized transaction list
26
+
27
+ Quicken can be configured to import all transfers, regardless of whether Ignore Transfers is selected when the file is imported. To do this, add a line to the file being imported into the Quicken account. Use a text editor or word processor to put the following line immediately after the header line at the top of the file:
28
+
29
+ !Option:AllXfr
30
+
31
+
32
+ Items for Non-Investment Accounts
33
+ Each item in a bank, cash, credit card, other liability, or other asset account must begin with a letter that indicates the field in the Quicken
34
+ register. The non-split items can be in any sequence:
35
+
36
+ Field Indicator Explanations
37
+ D Date
38
+ T Amount
39
+ C Cleared status
40
+ N Num (check or reference number)
41
+ P Payee
42
+ M Memo
43
+ A Address (up to five lines; the sixth line is an optional message)
44
+ L Category (Category/Subcategory/Transfer/Class)
45
+ S Category in split (Category/Transfer/Class)
46
+ E Memo in split
47
+ $ Dollar amount of split
48
+ ^ End of entry
49
+ Note: Repeat the S, E, and $ lines as many times as needed for additional items in a split. If an item is omitted from the transaction in the QIF file, Quicken treats it as a blank item.
50
+
51
+
52
+ Items for Investment Accounts
53
+ Field Indicator Explanation
54
+ D Date
55
+ N Action
56
+ Y Security
57
+ I Price
58
+ Q Quantity (number of shares or split ratio)
59
+ T Transaction amount
60
+ C Cleared status
61
+ P Text in the first line for transfers and reminders
62
+ M Memo
63
+ O Commission
64
+ L Account for the transfer
65
+ $ Amount transferred
66
+ ^ End of entry
67
+
68
+
69
+ Items for Account Information
70
+ The account header !Account is used in two places, at the start of an account list and the start of a list of transactions to specify to which account they belong.
71
+ Field Indicator Explanation
72
+ N Name
73
+ T Type of account
74
+ D Description
75
+ L Credit limit (only for credit card account)
76
+ / Statement balance date
77
+ $ Statement balance
78
+ ^ End of entry
79
+
80
+
81
+ Items for a Category List
82
+ Field Indicator Explanation
83
+ N Category name:subcategory name
84
+ D Description
85
+ T Tax related if included, not tax related if omitted
86
+ I Income category
87
+ E Expense category (if category is unspecified, Quicken assumes expense type)
88
+ B Budget amount (only in a Budget Amounts QIF file)
89
+ R Tax schedule information
90
+ ^ End of entry
91
+
92
+
93
+ Items for a Class List
94
+ Field Indicator Explanation
95
+ N Class name
96
+ D Description
97
+ ^ End of entry
98
+
99
+ Items for a Memorized Transaction List
100
+
101
+ Immediately preceding the ^ character, each entry must end with one of the following file indicators to specify the transaction type.
102
+ KC, KD, KP, KI, KE
103
+
104
+ With that exception, memorized transaction entries have the same format as regular transaction entries (non-investment accounts). However, the Date or Num field is included. All items are optional, but if an amortization record is included, all seven amortization lines must also be included.
105
+
106
+ Field Indicator Explanation
107
+ KC Check transaction
108
+ KD Deposit transaction
109
+ KP Payment transaction
110
+ KI Investment transaction
111
+ KE Electronic payee transaction
112
+ T Amount
113
+ C Cleared status
114
+ P Payee
115
+ M Memo
116
+ A Address
117
+ L Category or Transfer/Class
118
+ S Category/class in split
119
+ E Memo in split
120
+ $ Dollar amount of split
121
+ 1 Amortization: First payment date
122
+ 2 Amortization: Total years for loan
123
+ 3 Amortization: Number of payments already made
124
+ 4 Amortization: Number of periods per year
125
+ 5 Amortization: Interest rate
126
+ 6 Amortization: Current loan balance
127
+ 7 Amortization: Original loan amount
128
+ ^ End of entry
129
+
130
+
131
+ Examples of QIF files
132
+
133
+ Normal Transactions Example
134
+ Transaction Item Comment (not in file)
135
+ !Type:Bank Header
136
+ D6/ 1/94 Date
137
+ T-1,000.00 Amount
138
+ N1005 Check number
139
+ PBank Of Mortgage Payee
140
+ L[linda] Category
141
+ S[linda] First category in split
142
+ $-253.64 First amount in split
143
+ SMort Int Second category in split
144
+ $=746.36 Second amount in split
145
+ ^ End of transaction
146
+ D6/ 2/94 Date
147
+ T75.00 Amount
148
+ PDeposit Payee
149
+ ^ End of transaction
150
+ D6/ 3/94 Date
151
+ T-10.00 Amount
152
+ PAnthony Hopkins Payee
153
+ MFilm Memo
154
+ LEntertain Category
155
+ AP.O. Box 27027 Address (line 1)
156
+ ATucson, AZ Address (line 2)
157
+ A85726 Address (line 3)
158
+ A Address (line 4)
159
+ A Address (line 5)
160
+ A Address (line 6)
161
+ ^ End of transaction
162
+
163
+ Investment Example
164
+ Transaction Item Comment (not in file)
165
+ !Type:Invst Header line
166
+ D8/25/93 Date
167
+ NShrsIn Action (optional)
168
+ Yibm4 Security
169
+ I11.260 Price
170
+ Q88.81 Quantity
171
+ CX Cleared status
172
+ T1,000.00 Amount
173
+ MOpening Balance Memo
174
+ ^ End of transaction
175
+ D8/25/93 Date
176
+ NBuyX Action
177
+ Yibm4 Security
178
+ I11.030 Price
179
+ Q9.066 Quantity
180
+ T100.00 Amount
181
+ MEst. price as of 8/25/93 Memo
182
+ L[CHECKING] Account for transfer
183
+ $100.00 Amount transferred
184
+ ^ End of transaction
185
+
186
+ Memorized List Example
187
+ Transaction Item Comment (not in file)
188
+ !Type:Memorized Header line
189
+ T-50.00 Amount
190
+ POakwood Gardens Payee
191
+ MRent Memo
192
+ KC Check transaction
193
+ ^ End of transaction
194
+
195
+
196
+ Source :http://www.beansmart.com/quicken/Converting-Fidelity-CVS-to-QIF-or-OFX-for-Quicken-2007-5296-1.htm
197
+
198
+ Collected over the years:
199
+
200
+ QUICKEN INTERCHANGE FORMAT (QIF)
201
+
202
+ Overview
203
+ You can export transactions from a Quicken account register to a
204
+ specially formatted text file and import data to a Quicken register
205
+ from the same type of text file. This text file MUST be formatted
206
+ as a Quicken Interchange Format (QIF) file. For Quicken to
207
+ translate data from a text file into the Quicken register as
208
+ transactions, the data must be in the QIF format.
209
+
210
+ Procedure
211
+ Basic Procedures:
212
+ * Each transaction must end with a * symbol
213
+ * Each item in the transaction must appear on a separate line
214
+ * When Quicken exports an account register, it adds a line at the
215
+ top of the file that identifies the type of account. Here are
216
+ the header lines Quicken adds to the exported files:
217
+
218
+ !Type:Bank
219
+ !Type:Cash
220
+ !Type:CCard
221
+ !Type:Invst
222
+ !Type:Oth A
223
+ !Type:Oth L
224
+
225
+ * You can add a line to a file to be imported into Quicken account
226
+ to force Quicken to import all transfers, regardless of whether
227
+ Ignore Transfers is selected when the file is imported. Use a
228
+ test editor or word processor to put the following line right
229
+ after the header line at the top of the file:
230
+
231
+ !Option:AllXfr
232
+
233
+
234
+ Items for non-investment accounts
235
+
236
+ Each item in a bank, cash, credit card, other liability, or other
237
+ asset account must begin with a letter that indicates the field in
238
+ the Quicken register. The non-split items can be in any sequence:
239
+
240
+ D Date
241
+ T Amount
242
+ C Cleared status
243
+ N Number(check or reference number)
244
+ P Payee
245
+ A Address (up to five lines; the sixth line is an optional
246
+ message)
247
+ L Category (Category/Subcategory/Transfer/Class
248
+ S Category in split (Category/Transfer/Class)
249
+ E Memo in split
250
+ $ Dollar amount of split
251
+ ^ End of the entry
252
+
253
+ Items for investment accounts
254
+ D Date
255
+ N Action
256
+ Y Security
257
+ I Price
258
+ Q Quantity (Number of shares or split ratio)
259
+ C Cleared Status
260
+ P. Text in the first line for transfers and reminders
261
+ M Memo
262
+ O Commission
263
+ L Account for the transfer
264
+ $ Amount transferred
265
+ ^ End of the entry
266
+
267
+ Repeat the S, E, and $ lines as many times as needed for additional
268
+ items in a split. If an item is omitted from the transaction in the
269
+ QIF file, Quicken treats it as a blank item.
270
+
271
+
272
+
273
+ Examples of QIF files
274
+
275
+ Transaction Item Comment (not in file)
276
+ !Type:Bank Header line
277
+ D7/8/93 Date
278
+ T-1000.0 Transaction amount
279
+ CX Status in Cleared column
280
+ N255 Check Number
281
+ PFranks Plumbing Payee
282
+ AFranks Plumbing Address (first line)
283
+ A1234 Main St. Address (second line)
284
+ ASan Jose, CA 95123 Address (third line)
285
+ LHome Maint Category/Subcategory/Transfer/Class
286
+ ^ End of the transaction
287
+ D7/8/93 Date
288
+ T-75.46 Transaction amount
289
+ CX Status in Cleared column
290
+ N256 Check Number
291
+ PWalts Drug Payee
292
+ LSupplies First Category/Subcategory/Class in
293
+ the split
294
+ EOffices Supplies First memo in the split
295
+ $-51.00 First amount in the split
296
+ SMedicine Second Category/Subcategory/Class in the
297
+ split
298
+ EPrescription Drugs Second memo in the split
299
+ $-24.46 Second amount in the split
300
+ ^ End of the transaction
301
+
302
+ Transaction Item Comment (not in file)
303
+ !Type:Bank Header line
304
+ D8/25/93 Date
305
+ NShrsIn Action (optional)
306
+ Yibm4 Security
307
+ I11.260 Price
308
+ Q88.81 Quantity
309
+ CX Cleared Status
310
+ T1,000.00 Amount
311
+ MOpening Balance Memo
312
+ ^ End of the transaction
313
+ D8/25/93 Date
314
+ NBuyX Action
315
+ Yibm4 Security
316
+ I11.030 Price
317
+ Q9.066 Quantity
318
+ T100.00 Amount
319
+ MEst. price as of 8/25/93
320
+ Memo
321
+ L[CHECKING] Account for transfer
322
+ $100.00 Amount transferred
323
+ ^ End of the transaction
324
+
325
+ At Intuit, we highly recommend that you backup your Quicken data
326
+ regularly to protect against loss due to unexpected power failures,
327
+ diskette damage or other mishaps. If you need further assistance,
328
+ you may contact Intuit Technical Support at (415) 858-6050, Monday
329
+ through Friday between 5 am and 5 pm Pacific time.
330
+
331
+ --- Another entry of this info ---
332
+ Export headers for QIF files
333
+
334
+ Export headers in QIF files divide separate groups of items such
335
+ as accounts or transactions. They can also signify options. Export
336
+ headers follow the general format:
337
+
338
+ !<Header name>:<Export type>
339
+
340
+ Exportable accounts
341
+
342
+ The table below lists the types of accounts that can be exported
343
+ and their export headers:
344
+
345
+ Export Header Type of account
346
+ !Type:Bank Bank account
347
+ !Type:Cash Cash account
348
+ !Type:CCard Credit card account
349
+ !Type:Invst Investment account
350
+ !Type:Oth A Asset account
351
+ !Type:Oth L Liability account
352
+ !Type:Invoice Invoice account (business subtype of Oth A)
353
+ !Type:Tax Tax account (business subtype of Oth L)
354
+ !Type:Bill Bill account (business subtype of Oth L)
355
+ An account header is followed by transaction records if there are
356
+ any within the selected date range.
357
+
358
+ Exportable lists
359
+
360
+ The table below lists the types of lists that can be exported and
361
+ their export headers:
362
+
363
+ Export Header Type of list
364
+ !Type:Class Class list
365
+ !Type:Cat Category list
366
+ !Type:Memorized Memorized transactions list
367
+ !Type:Security Securities list
368
+ !Type:Prices Security Prices list
369
+ !Type:Budget Budgets list
370
+ !Type:Invitem Invoice items list
371
+ !Type:Template Business templates list
372
+ A list header is followed by records of the selected list type.
373
+
374
+ Options headers
375
+
376
+ Below is the option you can use, and its action:
377
+
378
+ Export Header Meaning
379
+ !Option:AllXfr Forces transfers to be imported, even if Ignore
380
+ Transfers is set.
381
+ Account headers
382
+
383
+ Export Header Meaning
384
+ !Option:AutoSwitch Start of the Accounts list
385
+ !Account Beginning of accounts list records
386
+ !Clear:AutoSwitch End of the Accounts list
387
+ !Account is followed by either a list of account records for the
388
+ Accounts list or a single account record for the selected account
389
+ transactions.
390
+
391
+ Copyright (c) 1999 Intuit, Inc.
392
+
393
+
394
+
395
+ Identifiers for non-investment accounts
396
+
397
+ Use these letters to identify specific items in a non-investment
398
+ 430 No such article
399
+ Howard Kaikow wrote:
400
+
401
+ Collected over the years:
402
+
403
+ QUICKEN INTERCHANGE FORMAT (QIF)
404
+
405
+ Overview
406
+ You can export transactions from a Quicken account register to a
407
+ specially formatted text file and import data to a Quicken register
408
+ from the same type of text file. This text file MUST be formatted
409
+ as a Quicken Interchange Format (QIF) file. For Quicken to
410
+ translate data from a text file into the Quicken register as
411
+ transactions, the data must be in the QIF format.
412
+
413
+ Procedure
414
+ Basic Procedures:
415
+ * Each transaction must end with a * symbol
416
+ * Each item in the transaction must appear on a separate line
417
+ * When Quicken exports an account register, it adds a line at the
418
+ top of the file that identifies the type of account. Here are
419
+ the header lines Quicken adds to the exported files:
420
+
421
+ !Type:Bank
422
+ !Type:Cash
423
+ !Type:CCard
424
+ !Type:Invst
425
+ !Type:Oth A
426
+ !Type:Oth L
427
+
428
+ * You can add a line to a file to be imported into Quicken account
429
+ to force Quicken to import all transfers, regardless of whether
430
+ Ignore Transfers is selected when the file is imported. Use a
431
+ test editor or word processor to put the following line right
432
+ after the header line at the top of the file:
433
+
434
+ !Option:AllXfr
435
+
436
+
437
+ Items for non-investment accounts
438
+
439
+ Each item in a bank, cash, credit card, other liability, or other
440
+ asset account must begin with a letter that indicates the field in
441
+ the Quicken register. The non-split items can be in any sequence:
442
+
443
+ D Date
444
+ T Amount
445
+ C Cleared status
446
+ N Number(check or reference number)
447
+ P Payee
448
+ A Address (up to five lines; the sixth line is an optional
449
+ message)
450
+ L Category (Category/Subcategory/Transfer/Class
451
+ S Category in split (Category/Transfer/Class)
452
+ E Memo in split
453
+ $ Dollar amount of split
454
+ ^ End of the entry
455
+
456
+ Items for investment accounts
457
+ D Date
458
+ N Action
459
+ Y Security
460
+ I Price
461
+ Q Quantity (Number of shares or split ratio)
462
+ C Cleared Status
463
+ P. Text in the first line for transfers and reminders
464
+ M Memo
465
+ O Commission
466
+ L Account for the transfer
467
+ $ Amount transferred
468
+ ^ End of the entry
469
+
470
+ Repeat the S, E, and $ lines as many times as needed for additional
471
+ items in a split. If an item is omitted from the transaction in the
472
+ QIF file, Quicken treats it as a blank item.
473
+
474
+
475
+
476
+ Examples of QIF files
477
+
478
+ Transaction Item Comment (not in file)
479
+ !Type:Bank Header line
480
+ D7/8/93 Date
481
+ T-1000.0 Transaction amount
482
+ CX Status in Cleared column
483
+ N255 Check Number
484
+ PFranks Plumbing Payee
485
+ AFranks Plumbing Address (first line)
486
+ A1234 Main St. Address (second line)
487
+ ASan Jose, CA 95123 Address (third line)
488
+ LHome Maint Category/Subcategory/Transfer/Class
489
+ ^ End of the transaction
490
+ D7/8/93 Date
491
+ T-75.46 Transaction amount
492
+ CX Status in Cleared column
493
+ N256 Check Number
494
+ PWalts Drug Payee
495
+ LSupplies First Category/Subcategory/Class in
496
+ the split
497
+ EOffices Supplies First memo in the split
498
+ $-51.00 First amount in the split
499
+ SMedicine Second Category/Subcategory/Class in the
500
+ split
501
+ EPrescription Drugs Second memo in the split
502
+ $-24.46 Second amount in the split
503
+ ^ End of the transaction
504
+
505
+ Transaction Item Comment (not in file)
506
+ !Type:Bank Header line
507
+ D8/25/93 Date
508
+ NShrsIn Action (optional)
509
+ Yibm4 Security
510
+ I11.260 Price
511
+ Q88.81 Quantity
512
+ CX Cleared Status
513
+ T1,000.00 Amount
514
+ MOpening Balance Memo
515
+ ^ End of the transaction
516
+ D8/25/93 Date
517
+ NBuyX Action
518
+ Yibm4 Security
519
+ I11.030 Price
520
+ Q9.066 Quantity
521
+ T100.00 Amount
522
+ MEst. price as of 8/25/93
523
+ Memo
524
+ L[CHECKING] Account for transfer
525
+ $100.00 Amount transferred
526
+ ^ End of the transaction
527
+
528
+ At Intuit, we highly recommend that you backup your Quicken data
529
+ regularly to protect against loss due to unexpected power failures,
530
+ diskette damage or other mishaps. If you need further assistance,
531
+ you may contact Intuit Technical Support at (415) 858-6050, Monday
532
+ through Friday between 5 am and 5 pm Pacific time.
533
+
534
+ --- Another entry of this info ---
535
+ Export headers for QIF files
536
+
537
+ Export headers in QIF files divide separate groups of items such
538
+ as accounts or transactions. They can also signify options. Export
539
+ headers follow the general format:
540
+
541
+ !<Header name>:<Export type>
542
+
543
+ Exportable accounts
544
+
545
+ The table below lists the types of accounts that can be exported
546
+ and their export headers:
547
+
548
+ Export Header Type of account
549
+ !Type:Bank Bank account
550
+ !Type:Cash Cash account
551
+ !Type:CCard Credit card account
552
+ !Type:Invst Investment account
553
+ !Type:Oth A Asset account
554
+ !Type:Oth L Liability account
555
+ !Type:Invoice Invoice account (business subtype of Oth A)
556
+ !Type:Tax Tax account (business subtype of Oth L)
557
+ !Type:Bill Bill account (business subtype of Oth L)
558
+ An account header is followed by transaction records if there are
559
+ any within the selected date range.
560
+
561
+ Exportable lists
562
+
563
+ The table below lists the types of lists that can be exported and
564
+ their export headers:
565
+
566
+ Export Header Type of list
567
+ !Type:Class Class list
568
+ !Type:Cat Category list
569
+ !Type:Memorized Memorized transactions list
570
+ !Type:Security Securities list
571
+ !Type:Prices Security Prices list
572
+ !Type:Budget Budgets list
573
+ !Type:Invitem Invoice items list
574
+ !Type:Template Business templates list
575
+ A list header is followed by records of the selected list type.
576
+
577
+ Options headers
578
+
579
+ Below is the option you can use, and its action:
580
+
581
+ Export Header Meaning
582
+ !Option:AllXfr Forces transfers to be imported, even if Ignore
583
+ Transfers is set.
584
+ Account headers
585
+
586
+ Export Header Meaning
587
+ !Option:AutoSwitch Start of the Accounts list
588
+ !Account Beginning of accounts list records
589
+ !Clear:AutoSwitch End of the Accounts list
590
+ !Account is followed by either a list of account records for the
591
+ Accounts list or a single account record for the selected account
592
+ transactions.
593
+
594
+ Copyright (c) 1999 Intuit, Inc.
595
+
596
+
597
+
598
+ Identifiers for non-investment accounts
599
+
600
+ Use these letters to identify specific items in a non-investment
601
+ account transaction. Each line in the transaction must begin with
602
+ one of these letters:
603
+
604
+ Letter What it means
605
+ D Date
606
+ T Amount of transaction
607
+ U Amount of transaction (higher possible value than T)
608
+ C Cleared status
609
+ N Number (check or reference)
610
+ P Payee/description
611
+ M Memo
612
+ A Address (up to 5 lines; 6th line is an optional message)
613
+ L Category/class or transfer/class
614
+ S Category in split (category/class or transfer/class)
615
+ E Memo in split
616
+ $ Dollar amount of split
617
+ % Percentage of split if percentages are used
618
+ F Reimbursable business expense flag
619
+ ^ End of entry
620
+ Repeat the S, E, % and $ lines as many times as necessary for
621
+ additional items in a split. If an item is omitted from the
622
+ transaction in the QIF file, Quicken treats it as a blank item.
623
+
624
+ Copyright (c) 1999 Intuit, Inc.
625
+
626
+
627
+ Identifiers for investment accounts
628
+
629
+ Use these letters to identify specific items in an investment
630
+ account transaction. Each line in the transaction must begin with
631
+ one of these letters:
632
+
633
+ Letter What it means
634
+ D Date (optional)
635
+ N Action
636
+ Y Security
637
+ I Price
638
+ Q Quantity (# of shares or split ratio)
639
+ C Cleared status
640
+ P 1st line text for transfers/reminders
641
+ M Memo
642
+ O Commission
643
+ L For MiscIncX or MiscExpX actions:Category/class followed by
644
+ |transfer/class of the transaction
645
+ For MiscInc or MiscExp actions:Category/class of the transaction
646
+ For all other actions:Transfer/class of the transactions
647
+ T Amount of transaction
648
+ U Amount of transaction (higher possible value than T)
649
+ $ Amount transferred
650
+ ^ End of entry
651
+ If an item is omitted from the transaction in the QIF file,
652
+ Quicken treats it as a blank item.
653
+
654
+ Copyright (c) 1999 Intuit, Inc.
655
+
656
+
657
+
658
+ Identifiers for memorized transaction items
659
+
660
+ Use these letters to identify specific items in a memorized
661
+ transaction. Each line in the transaction must begin with one of
662
+ these letters or combination of letters:
663
+
664
+ Memorized transaction identifiers
665
+
666
+ The table below lists the identifiers for Memorized Transaction
667
+ items and what they mean:
668
+
669
+ Letter What it means
670
+ K Transaction type
671
+ KI Memorized investment transaction
672
+ KE Memorized regular electronic payment transaction
673
+ KC Memorized regular write checks transaction
674
+ KP Memorized regular payment transaction
675
+ KD Memorized regular deposit transaction
676
+ Q Quantity (number of new shares for a split)
677
+ R Quantity (number of old shares for a split)
678
+ You can also use the identifiers for investment and non-investment
679
+ transactions, as necessary. Electronic payments, write checks,
680
+ payments, and deposits are regular transaction types.
681
+ Memorized loan payment also supports the following identifiers:
682
+
683
+ Letter What it means
684
+ 1 First payment date
685
+ 2 Total years of the loan
686
+ 3 Number of payments made
687
+ 4 Payment periods per year
688
+ 5 Loan rate
689
+ 6 Current balance of the loan
690
+ 7 Original balance of the loan
691
+
692
+ Copyright (c) 1999 Intuit, Inc.
693
+
694
+
695
+ Identifiers for business transaction items (Home & Business)
696
+
697
+ Use these letters to identify specific business-related items in a
698
+ non-investment account transaction. Each line in the transaction
699
+ must begin with one of these letter combinations:
700
+
701
+ Letter What it means
702
+ XI Invoice type
703
+ XE Payment due date
704
+ XU Number of payments
705
+ XD Date for a payment
706
+ XY Payment amount
707
+ XC Sales tax Category
708
+ XR Sales tax rate
709
+ XT Sales Tax amount
710
+ XP PO number
711
+ XA Shipping/Vendor address (up to 5 lines)
712
+ XM Customer message
713
+ XK Default split class
714
+ XN Name of invoice item
715
+ X$ Price per item of a split
716
+ X# Number of items in a split
717
+ XS Split item description
718
+ XFT Taxable split item flag
719
+ ^ End of entry
720
+ Repeat the XS, XK, X Ft, X# and X$ lines as many times as
721
+ necessary for additional items in a split. If an item is omitted
722
+ from the transaction in the QIF file, Quicken treats it as a blank
723
+ item.
724
+
725
+ Copyright (c) 1999 Intuit, Inc.
726
+
727
+
728
+
@@ -0,0 +1,45 @@
1
+ = Library for reading Quicken Interchange Format (QIF) files
2
+
3
+ * http://github.com/jemmyw/Qif
4
+
5
+ === INSTALL:
6
+
7
+ * sudo gem install qif
8
+
9
+ === DOCUMENTATION:
10
+
11
+ * http://rdoc.info/gems/qif/0.2/frames
12
+
13
+ === EXAMPLE:
14
+
15
+ require 'qif'
16
+ qif = Qif::Reader.new(open('/path/to/file.qif'))
17
+ qif.each do |transaction|
18
+ puts [transaction.name, transaction.description, transaction.amount].join(", ")
19
+ end
20
+
21
+ === LICENSE:
22
+
23
+ Copyright (c) 2010 Jeremy Wells
24
+
25
+ Permission is hereby granted, free of charge, to any person
26
+ obtaining a copy of this software and associated documentation
27
+ files (the "Software"), to deal in the Software without
28
+ restriction, including without limitation the rights to use,
29
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
30
+ copies of the Software, and to permit persons to whom the
31
+ Software is furnished to do so, subject to the following
32
+ conditions:
33
+
34
+ The above copyright notice and this permission notice shall be
35
+ included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
39
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
41
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
42
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
43
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44
+ OTHER DEALINGS IN THE SOFTWARE.
45
+
@@ -25,16 +25,20 @@ module Qif
25
25
  }
26
26
 
27
27
  class UnknownAccountType < StandardError; end
28
-
28
+ class UnrecognizedData < StandardError; end
29
+
29
30
  # Create a new Qif::Reader object. The data argument must be
30
31
  # either an IO object or a String containing the Qif file data.
31
32
  #
32
- # The optional format argument specifies the date format in the file. Giving a format will force it, otherwise the format will guissed reading the transactions in the file, this
33
- # defaults to 'dd/mm/yyyy' if guessing method fails.
33
+ # The optional format argument specifies the date format in the file.
34
+ # Giving a format will force it, otherwise the format will guissed
35
+ # reading the transactions in the file, this defaults to 'dd/mm/yyyy'
36
+ # if guessing method fails.
34
37
  def initialize(data, format = nil)
35
38
  @data = data.respond_to?(:read) ? data : StringIO.new(data.to_s)
36
39
  @format = DateFormat.new(format || guess_date_format || 'dd/mm/yyyy')
37
40
  read_header
41
+ raise(UnrecognizedData, "Provided data doesn't seems to represent a QIF file") unless @header
38
42
  raise(UnknownAccountType, "Unknown account type. Should be one of followings :\n#{SUPPORTED_ACCOUNTS.keys.inspect}") unless SUPPORTED_ACCOUNTS.keys.collect(&:downcase).include? @header.downcase
39
43
  reset
40
44
  end
@@ -130,6 +134,7 @@ module Qif
130
134
  unless line =~ /^\^/
131
135
  rewind_to @data.lineno - 1
132
136
  end
137
+ headers
133
138
  end
134
139
 
135
140
  def read_transaction
@@ -4,18 +4,18 @@ module Qif
4
4
  # The Qif::Transaction class represents transactions in a qif file.
5
5
  class Transaction
6
6
  SUPPORTED_FIELDS = {
7
- :date => {"D" => "Date"},
8
- :amount => {"T" => "Amount"},
9
- :status => {"C" => "Cleared status"},
10
- :number => {"N" => "Num (check or reference number)"},
11
- :payee => {"P" => "Payee"},
12
- :memo => {"M" => "Memo"},
13
- :adress => {"A" => "Address (up to five lines; the sixth line is an optional message)"},
14
- :category => {"L" => "Category (Category/Subcategory/Transfer/Class)"},
15
- :split_category => {"S" => "Category in split (Category/Transfer/Class)"},
16
- :split_memo => {"E" => "Memo in split"},
17
- :split_amount => {"$" => "Dollar amount of split"},
18
- :end => {"^" => "End of entry"}
7
+ :date => {"D" => "Date" },
8
+ :amount => {"T" => "Amount" },
9
+ :status => {"C" => "Cleared status" },
10
+ :number => {"N" => "Num (check or reference number)" },
11
+ :payee => {"P" => "Payee" },
12
+ :memo => {"M" => "Memo" },
13
+ :adress => {"A" => "Address (up to five lines; the sixth line is an optional message)" },
14
+ :category => {"L" => "Category (Category/Subcategory/Transfer/Class)" },
15
+ :split_category => {"S" => "Category in split (Category/Transfer/Class)" },
16
+ :split_memo => {"E" => "Memo in split" },
17
+ :split_amount => {"$" => "Dollar amount of split" },
18
+ :end => {"^" => "End of entry" }
19
19
  }
20
20
  DEPRECATION_FIELDS = {
21
21
  :reference => :payee,
@@ -43,7 +43,7 @@ module Qif
43
43
  next unless current = instance_variable_get("@#{k}")
44
44
  field = v.keys
45
45
  case current.class.to_s
46
- when "Time"
46
+ when "Time", "Date", "DateTime"
47
47
  "#{field}#{DateFormat.new(format).format(current)}"
48
48
  when "Float"
49
49
  "#{field}#{'%.2f'%current}"
@@ -18,26 +18,45 @@ module Qif
18
18
 
19
19
  # Open a qif file for writing and yield a Qif::Writer instance.
20
20
  # For parameters see #new.
21
- def self.open(path, type = 'Bank', format = 'dd/mm/yyyy')
21
+ def self.open(path, type = 'Bank', format = 'dd/mm/yyyy', &block)
22
22
  File.open(path, 'w') do |file|
23
- writer = self.new(file, type, format)
24
- yield writer
25
- writer.write
23
+ self.new(file, type, format, &block)
26
24
  end
27
25
  end
28
26
 
29
27
  # Create a new Qif::Writer. Expects an IO object or a filepath.
28
+ # Can optionally take a block which will yield the writer and
29
+ # automatically call write afterwards.
30
30
  #
31
31
  # Parameters:
32
32
  #
33
33
  # * <tt>io</tt> - An IO object or filepath
34
34
  # * <tt>type</tt> - Used to write the header, defaults to 'Bank'
35
35
  # * <tt>format</tt> - The format of dates in the qif file, defaults to 'dd/mm/yyyy'. Also accepts 'mm/dd/yyyy'
36
+ #
37
+ # Usage:
38
+ # buffer = StringIO.new
39
+ # writer = Qif::Writer.new(buffer)
40
+ # writer << Qif::Transaction.new(:date => Time.now, :amount => 10.0, :name => 'Credit')
41
+ # writer.write
42
+ # puts buffer
43
+ #
44
+ # Usage with block:
45
+ # buffer = StringIO.new
46
+ # Qif::Writer.new(buffer) do |writer|
47
+ # writer << Qif::Transaction.new(:date => Time.now, :amount => 10.0, :name => 'Credit')
48
+ # end
49
+ # puts buffer
36
50
  def initialize(io, type = 'Bank', format = 'dd/mm/yyyy')
37
51
  @io = io.respond_to?(:write) ? io : File.open(io, 'w')
38
52
  @type = type
39
53
  @format = format
40
54
  @transactions = []
55
+
56
+ if block_given?
57
+ yield self
58
+ self.write
59
+ end
41
60
  end
42
61
 
43
62
  # Add a transaction for writing
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{qif}
5
- s.version = "1.0"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jeremy Wells"]
9
- s.date = %q{2011-02-19}
9
+ s.date = %q{2011-03-07}
10
10
  s.description = %q{A library for reading and writing quicken QIF files.}
11
11
  s.email = %q{jemmyw@gmail.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/qif.rb", "lib/qif/date_format.rb", "lib/qif/reader.rb", "lib/qif/transaction.rb", "lib/qif/writer.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "lib/qif.rb", "lib/qif/date_format.rb", "lib/qif/reader.rb", "lib/qif/transaction.rb", "lib/qif/writer.rb", "qif.gemspec", "spec/fixtures/3_records_ddmmyy.qif", "spec/fixtures/3_records_ddmmyyyy.qif", "spec/fixtures/3_records_mmddyy.qif", "spec/fixtures/3_records_mmddyyyy.qif", "spec/lib/date_format_spec.rb", "spec/lib/reader_spec.rb", "spec/lib/transaction_spec.rb", "spec/lib/writer_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
14
- s.homepage = %q{}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/qif.rb", "lib/qif/date_format.rb", "lib/qif/reader.rb", "lib/qif/transaction.rb", "lib/qif/writer.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "QIF_references", "README.rdoc", "Rakefile", "lib/qif.rb", "lib/qif/date_format.rb", "lib/qif/reader.rb", "lib/qif/transaction.rb", "lib/qif/writer.rb", "spec/fixtures/3_records_ddmmyy.qif", "spec/fixtures/3_records_ddmmyyyy.qif", "spec/fixtures/3_records_dmyy.qif", "spec/fixtures/3_records_invalid_header.qif", "spec/fixtures/3_records_mmddyy.qif", "spec/fixtures/3_records_mmddyyyy.qif", "spec/fixtures/3_records_separator.qif", "spec/fixtures/not_a_QIF_file.txt", "spec/fixtures/quicken_investment_account.qif", "spec/fixtures/quicken_non_investement_account.qif", "spec/lib/date_format_spec.rb", "spec/lib/reader_spec.rb", "spec/lib/transaction_spec.rb", "spec/lib/writer_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "qif.gemspec"]
14
+ s.homepage = %q{http://qif.github.com/qif/}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qif", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{qif}
18
- s.rubygems_version = %q{1.5.0}
18
+ s.rubygems_version = %q{1.6.1}
19
19
  s.summary = %q{A library for reading and writing quicken QIF files.}
20
20
 
21
21
  if s.respond_to? :specification_version then
@@ -0,0 +1,19 @@
1
+ !Type:Bank
2
+ D1/1/10
3
+ T-10.00
4
+ LDebit
5
+ PDescription
6
+ MReference
7
+ ^
8
+ D1/6/10
9
+ T-20.00
10
+ LDebit
11
+ PDescription
12
+ MReference
13
+ ^
14
+ D29/12/10
15
+ T30.00
16
+ LCredit
17
+ PDescription
18
+ MReference
19
+ ^
@@ -0,0 +1,20 @@
1
+ !Type:Bank
2
+ ^
3
+ D01/01/10
4
+ T-10.00
5
+ LDebit
6
+ PDescription
7
+ MReference
8
+ ^
9
+ D01/06/10
10
+ T-20.00
11
+ LDebit
12
+ PDescription
13
+ MReference
14
+ ^
15
+ D29/12/10
16
+ T30.00
17
+ LCredit
18
+ PDescription
19
+ MReference
20
+ ^
@@ -0,0 +1,19 @@
1
+ !Type:Bank
2
+ D01/01/2010
3
+ T-1,010.00
4
+ LDebit
5
+ PDescription
6
+ MReference
7
+ ^
8
+ D01/06/2010
9
+ T-30,020.00
10
+ LDebit
11
+ PDescription
12
+ MReference
13
+ ^
14
+ D29/12/2010
15
+ T30.00
16
+ LCredit
17
+ PDescription
18
+ MReference
19
+ ^
@@ -0,0 +1,3 @@
1
+ Tchen tenterait-il de lever la moustiquaire ? Frapperait-il au travers ? L’angoisse lui tordait l’estomac ; il connaissait sa propre fermeté, mais n’était capable en cet instant que d’y songer avec hébétude, fasciné par ce tas de mousseline blanche qui tombait du plafond sur un corps moins visible qu’une ombre, et d’où sortait seulement ce pied à demi incliné par le sommeil, vivant quand même — de la chair d’homme. La seule lumière venait du building voisin : un grand rectangle d’électricité pâle, coupé par les barreaux de la fenêtre dont l’un rayait le lit juste au-dessous du pied comme pour en accentuer le volume et la vie. Quatre ou cinq klaxons grincèrent à la fois. Découvert ? Combattre, combattre des ennemis qui se défendent, des ennemis éveillés !
2
+
3
+ Incipit de "La Condition humaine", André Malraux, 1933
@@ -0,0 +1,20 @@
1
+ !Type:Invst
2
+ D8/25/93
3
+ NShrsIn
4
+ Yibm4
5
+ I11.260
6
+ Q88.81
7
+ CX
8
+ T1,000.00
9
+ MOpening
10
+ ^
11
+ D8/25/93
12
+ NBuyX
13
+ Yibm4
14
+ I11.030
15
+ Q9.066
16
+ T100.00
17
+ MEst. price as of 8/25/93
18
+ L[CHECKING]
19
+ $100.00
20
+ ^
@@ -0,0 +1,30 @@
1
+ !Type:Bank
2
+ D6/1/94
3
+ T-1,000.00
4
+ CX
5
+ N1005
6
+ PBank Of Mortgage
7
+ MMemo
8
+ L[linda]
9
+ S[linda]
10
+ ECash
11
+ $-253.64
12
+ SMort Int
13
+ $=746.36
14
+ ^
15
+ D6/2/94
16
+ T75.00
17
+ PDeposit
18
+ ^
19
+ D6/3/94
20
+ T-10.00
21
+ PAnthony Hopkins
22
+ MFilm
23
+ LEntertain
24
+ AP.O. Box 27027
25
+ ATucson, AZ
26
+ A85726
27
+ A
28
+ A
29
+ A
30
+ ^
@@ -55,7 +55,9 @@ describe Qif::Reader do
55
55
  it 'should reject the wrong account type !Type:Invst and raise an UnknownAccountType exception' do
56
56
  expect{ Qif::Reader.new(open('spec/fixtures/quicken_investment_account.qif')) }.to raise_error(Qif::Reader::UnknownAccountType)
57
57
  end
58
-
58
+ it 'should reject the wrong file and raise an UnrecognizedData exception' do
59
+ expect{ Qif::Reader.new(open('spec/fixtures/not_a_QIF_file.txt')) }.to raise_error(Qif::Reader::UnrecognizedData)
60
+ end
59
61
  it 'should guess the date format dd/mm/yyyy' do
60
62
  @instance = Qif::Reader.new(open('spec/fixtures/3_records_ddmmyyyy.qif'))
61
63
  @instance.guess_date_format.should == 'dd/mm/yyyy'
@@ -41,6 +41,38 @@ describe Qif::Writer do
41
41
  end
42
42
  end
43
43
  end
44
+ describe '::new' do
45
+ it 'should yield a Qif::Writer' do
46
+ ran = false
47
+ Qif::Writer.new(@io) do |writer|
48
+ ran = true
49
+ writer.should be_a(Qif::Writer)
50
+ end
51
+ ran.should be_true
52
+ end
53
+
54
+ it 'should write the transactions' do
55
+ date = Time.now
56
+
57
+ Qif::Writer.new(@io) do |writer|
58
+ writer << Qif::Transaction.new(:date => date, :amount => 10.0, :category => 'Credit')
59
+ end
60
+
61
+ @buffer.should include('D%s' % date.strftime('%d/%m/%Y'))
62
+ @buffer.should include('T10.0')
63
+ @buffer.should include('LCredit')
64
+ end
65
+
66
+ it 'should perform a File.open on the given path' do
67
+ File.should_receive(:open).with(@path, 'w')
68
+ Qif::Writer.open(@path) do |writer|
69
+ end
70
+ end
71
+ end
72
+
73
+
74
+
75
+
44
76
 
45
77
  describe '#write' do
46
78
  it 'should write the header' do
@@ -64,4 +96,4 @@ describe Qif::Writer do
64
96
  @instance.close
65
97
  end
66
98
  end
67
- end
99
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qif
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- version: "1.0"
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jeremy Wells
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-19 00:00:00 +13:00
18
+ date: 2011-03-07 00:00:00 +13:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -27,6 +28,7 @@ extensions: []
27
28
  extra_rdoc_files:
28
29
  - CHANGELOG
29
30
  - LICENSE
31
+ - README.rdoc
30
32
  - lib/qif.rb
31
33
  - lib/qif/date_format.rb
32
34
  - lib/qif/reader.rb
@@ -36,25 +38,33 @@ files:
36
38
  - CHANGELOG
37
39
  - LICENSE
38
40
  - Manifest
41
+ - QIF_references
42
+ - README.rdoc
39
43
  - Rakefile
40
44
  - lib/qif.rb
41
45
  - lib/qif/date_format.rb
42
46
  - lib/qif/reader.rb
43
47
  - lib/qif/transaction.rb
44
48
  - lib/qif/writer.rb
45
- - qif.gemspec
46
49
  - spec/fixtures/3_records_ddmmyy.qif
47
50
  - spec/fixtures/3_records_ddmmyyyy.qif
51
+ - spec/fixtures/3_records_dmyy.qif
52
+ - spec/fixtures/3_records_invalid_header.qif
48
53
  - spec/fixtures/3_records_mmddyy.qif
49
54
  - spec/fixtures/3_records_mmddyyyy.qif
55
+ - spec/fixtures/3_records_separator.qif
56
+ - spec/fixtures/not_a_QIF_file.txt
57
+ - spec/fixtures/quicken_investment_account.qif
58
+ - spec/fixtures/quicken_non_investement_account.qif
50
59
  - spec/lib/date_format_spec.rb
51
60
  - spec/lib/reader_spec.rb
52
61
  - spec/lib/transaction_spec.rb
53
62
  - spec/lib/writer_spec.rb
54
63
  - spec/spec.opts
55
64
  - spec/spec_helper.rb
65
+ - qif.gemspec
56
66
  has_rdoc: true
57
- homepage: ""
67
+ homepage: http://qif.github.com/qif/
58
68
  licenses: []
59
69
 
60
70
  post_install_message:
@@ -89,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
99
  requirements: []
90
100
 
91
101
  rubyforge_project: qif
92
- rubygems_version: 1.5.0
102
+ rubygems_version: 1.6.1
93
103
  signing_key:
94
104
  specification_version: 3
95
105
  summary: A library for reading and writing quicken QIF files.