qif 0.3 → 0.4

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
+ v0.4 Follow QIF specification that an end of entry should not appear under a
2
+ header [jscipione]
3
+
1
4
  v0.3 Allow two digit years [caleb]
2
5
 
3
6
  v0.2 Added documentation
@@ -81,9 +81,29 @@ module Qif
81
81
  read_transaction
82
82
  end
83
83
  end
84
+
85
+ # lineno= and seek don't seem
86
+ # to work with StringIO
87
+ def rewind_to(n)
88
+ @data.rewind
89
+ while @data.lineno != n
90
+ @data.readline
91
+ end
92
+ end
84
93
 
85
94
  def read_header
86
- @header = read_record
95
+ headers = []
96
+ begin
97
+ line = @data.readline.strip
98
+ headers << line.strip if line =~ /^!/
99
+ end until line !~ /^!/
100
+
101
+ @header = headers.shift
102
+ @options = headers.map{|h| h.split(':').last }
103
+
104
+ unless line =~ /^\^/
105
+ rewind_to @data.lineno - 1
106
+ end
87
107
  end
88
108
 
89
109
  def read_transaction
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{qif}
5
- s.version = "0.3"
5
+ s.version = "0.4"
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{2010-11-09}
9
+ s.date = %q{2010-11-24}
10
10
  s.description = %q{A library for reading and writing quicken QIF files.}
11
11
  s.email = %q{jemmyw@gmail.com}
12
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
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
14
  s.homepage = %q{}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qif"]
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
18
  s.rubygems_version = %q{1.3.7}
@@ -1,5 +1,4 @@
1
1
  !Type:Bank
2
- ^
3
2
  D01/01/10
4
3
  T-10.00
5
4
  LDebit
@@ -17,4 +16,4 @@ T30.00
17
16
  LCredit
18
17
  PDescription
19
18
  MReference
20
- ^
19
+ ^
@@ -1,5 +1,4 @@
1
1
  !Type:Bank
2
- ^
3
2
  D01/01/2010
4
3
  T-10.00
5
4
  LDebit
@@ -17,4 +16,4 @@ T30.00
17
16
  LCredit
18
17
  PDescription
19
18
  MReference
20
- ^
19
+ ^
@@ -1,5 +1,4 @@
1
1
  !Type:Bank
2
- ^
3
2
  D01/01/10
4
3
  T-10.00
5
4
  LDebit
@@ -17,4 +16,4 @@ T30.00
17
16
  LCredit
18
17
  PDescription
19
18
  MReference
20
- ^
19
+ ^
@@ -1,5 +1,4 @@
1
1
  !Type:Bank
2
- ^
3
2
  D01/01/2010
4
3
  T-10.00
5
4
  LDebit
@@ -17,4 +16,4 @@ T30.00
17
16
  LCredit
18
17
  PDescription
19
18
  MReference
20
- ^
19
+ ^
@@ -1,48 +1,57 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
+ shared_examples_for "3 record files" do
4
+ it 'should have 3 records' do
5
+ instance.size.should == 3
6
+ end
7
+
8
+ it 'should have a debit of $10 on the 1st of January 2010' do
9
+ transaction = instance.transactions.detect{|t| t.date == Time.mktime(2010, 1, 1)}
10
+ transaction.should_not be_nil
11
+ transaction.name.should == 'Debit'
12
+ transaction.amount.should == -10.0
13
+ end
14
+
15
+ it 'should have a debit of $20 on the 1st of June 1020' do
16
+ transaction = instance.transactions.detect{|t| t.date == Time.mktime(2010, 6, 1)}
17
+ transaction.should_not be_nil
18
+ transaction.name.should == 'Debit'
19
+ transaction.amount.should == -20.0
20
+ end
21
+
22
+ it 'should have a credit of $30 on the 29th of December 2010' do
23
+ transaction = instance.transactions.detect{|t| t.date == Time.mktime(2010, 12, 29)}
24
+ transaction.should_not be_nil
25
+ transaction.name.should == 'Credit'
26
+ transaction.amount.should == 30.0
27
+ end
28
+
29
+ describe '#each' do
30
+ it 'should yield each transaction' do
31
+ transactions = []
32
+ instance.each do |t|
33
+ transactions << t
34
+ end
35
+ transactions.should == instance.transactions
36
+ end
37
+ end
38
+ end
39
+
3
40
  describe Qif::Reader do
4
41
  %w(dd/mm/yyyy mm/dd/yyyy dd/mm/yy mm/dd/yy).each do |format|
5
- before do
6
- @file = 'spec/fixtures/3_records_%s.qif' % format.gsub('/', '')
7
- @instance = Qif::Reader.new(open(@file), format)
8
- end
9
-
10
- it 'should have 3 records' do
11
- @instance.size.should == 3
12
- end
13
-
14
- it 'should have a debit of $10 on the 1st of January 2010' do
15
- transaction = @instance.transactions.detect{|t| t.date == Time.mktime(2010, 1, 1)}
16
- transaction.should_not be_nil
17
- transaction.name.should == 'Debit'
18
- transaction.amount.should == -10.0
19
- end
20
-
21
- it 'should have a debit of $20 on the 1st of June 1020' do
22
- transaction = @instance.transactions.detect{|t| t.date == Time.mktime(2010, 6, 1)}
23
- transaction.should_not be_nil
24
- transaction.name.should == 'Debit'
25
- transaction.amount.should == -20.0
26
- end
27
-
28
- it 'should have a credit of $30 on the 29th of December 2010' do
29
- transaction = @instance.transactions.detect{|t| t.date == Time.mktime(2010, 12, 29)}
30
- transaction.should_not be_nil
31
- transaction.name.should == 'Credit'
32
- transaction.amount.should == 30.0
33
- end
34
-
35
- describe '#each' do
36
- it 'should yield each transaction' do
37
- transactions = []
38
- @instance.each do |t|
39
- transactions << t
40
- end
41
- transactions.should == @instance.transactions
42
+ context "when format is #{format}" do
43
+ it_behaves_like "3 record files" do
44
+ let(:instance) { Qif::Reader.new(open('spec/fixtures/3_records_%s.qif' % format.gsub('/', '')).read, format) }
42
45
  end
43
46
  end
44
47
  end
45
-
48
+
49
+ context "it should still work when the record header is followed by an invalid transaction terminator" do
50
+ it_behaves_like "3 record files" do
51
+ let(:instance) { Qif::Reader.new(open('spec/fixtures/3_records_invalid_header.qif'), 'dd/mm/yy') }
52
+ end
53
+ end
54
+
46
55
  it 'should initialize with an io object' do
47
56
  @instance = Qif::Reader.new(open('spec/fixtures/3_records_ddmmyyyy.qif'))
48
57
  @instance.size.should == 3
@@ -57,4 +66,4 @@ describe Qif::Reader do
57
66
  @instance = Qif::Reader.new(open('spec/fixtures/3_records_ddmmyyyy.qif'), 'mm/dd/yyyy')
58
67
  @instance.size.should == 2
59
68
  end
60
- end
69
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qif
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremy Wells
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-09 00:00:00 +13:00
17
+ date: 2010-11-24 00:00:00 +13:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -63,6 +63,8 @@ rdoc_options:
63
63
  - --inline-source
64
64
  - --title
65
65
  - Qif
66
+ - --main
67
+ - README.rdoc
66
68
  require_paths:
67
69
  - lib
68
70
  required_ruby_version: !ruby/object:Gem::Requirement