sie 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -61,11 +61,11 @@ class YourDataSource
61
61
  end
62
62
 
63
63
  def balance_account_numbers
64
- [ "1500", "2400" ]
64
+ [ 1500, 2400 ]
65
65
  end
66
66
 
67
67
  def closing_account_numbers
68
- [ "3100" ]
68
+ [ 3100 ]
69
69
  end
70
70
 
71
71
  # Used to calculate balance before (and on) the given date for an account.
@@ -86,11 +86,11 @@ class YourDataSource
86
86
  booked_on: Date.today, description: "Invoice 1",
87
87
  voucher_lines: [
88
88
  {
89
- account_number: "1500", amount: 512.0,
89
+ account_number: 1500, amount: 512.0,
90
90
  booked_on: Date.today, description: "Item 1"
91
91
  },
92
92
  {
93
- account_number: "3100", amount: -512.0,
93
+ account_number: 3100, amount: -512.0,
94
94
  booked_on: Date.today, description: "Item 1"
95
95
  },
96
96
  ]
@@ -1,24 +1,43 @@
1
+ require "active_support/core_ext/time"
2
+ require "active_support/core_ext/date"
3
+
1
4
  class Sie::Document
2
5
  class FinancialYears
3
- def self.between(start_month, from_date, to_date)
4
- result = []
6
+ method_object :between,
7
+ :start_month, :from_date, :to_date
8
+
9
+ def between
10
+ from_date.upto(to_date).map { |date|
11
+ financial_year = FinancialYear.new(date, start_month)
12
+ financial_year.date_range(from_date, to_date)
13
+ }.uniq
14
+ end
15
+ end
5
16
 
6
- from_date.upto(to_date) do |date|
7
- next if result.any? { |r| r.cover?(date) }
17
+ class FinancialYear
18
+ pattr_initialize :date, :start_month
8
19
 
9
- start_of_year = Date.new(date.year, start_month, 1)
10
- start_of_year = start_of_year <= date ? start_of_year : (start_of_year << 12)
20
+ def date_range(from_date, to_date)
21
+ first_date = [ start_of_year, from_date ].max
22
+ last_date = [ end_of_year, to_date ].min
23
+ (first_date.beginning_of_month..last_date.end_of_month)
24
+ end
11
25
 
12
- a_year_later = start_of_year >> 11
13
- end_of_year = Date.new(a_year_later.year, a_year_later.month, -1)
26
+ private
14
27
 
15
- first_date = [start_of_year, from_date].max
16
- last_date = [end_of_year, to_date].min
28
+ def start_of_year
29
+ start_of_year = Date.new(date.year, start_month, 1)
17
30
 
18
- result << (first_date..last_date)
31
+ if start_of_year <= date
32
+ start_of_year
33
+ else
34
+ start_of_year << 12
19
35
  end
36
+ end
20
37
 
21
- result
38
+ def end_of_year
39
+ a_year_later = start_of_year >> 11
40
+ Date.new(a_year_later.year, a_year_later.month, -1)
22
41
  end
23
42
  end
24
43
  end
@@ -1,3 +1,3 @@
1
1
  module Sie
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Command to run the specs the correct way when triggered from the turbux vim plugin.
4
+
5
+ command = "rspec #{ARGV.first}"
6
+ exit(1) unless system(command)
@@ -28,11 +28,21 @@ describe Sie::Document::FinancialYears, ".between" do
28
28
  Sie::Document::FinancialYears.between(
29
29
  5,
30
30
  Date.new(2011, 9, 1),
31
- Date.new(2014, 1, 10)
31
+ Date.new(2014, 1, 31)
32
32
  ).should == [
33
33
  Date.new(2011, 9, 1)..Date.new(2012, 4, 30),
34
34
  Date.new(2012, 5, 1)..Date.new(2013, 4, 30),
35
- Date.new(2013, 5, 1)..Date.new(2014, 1, 10),
35
+ Date.new(2013, 5, 1)..Date.new(2014, 1, 31),
36
+ ]
37
+ end
38
+
39
+ it "normalizes start and end date for compatibility with other systems" do
40
+ Sie::Document::FinancialYears.between(
41
+ 1,
42
+ Date.new(2011, 9, 15),
43
+ Date.new(2011, 10, 10)
44
+ ).should == [
45
+ Date.new(2011, 9, 1)..Date.new(2011, 10, 31),
36
46
  ]
37
47
  end
38
48
  end
@@ -17,15 +17,15 @@ describe Sie::Document, "#render" do
17
17
  {
18
18
  creditor: false, type: :invoice, number: 1, booked_on: from_date + 2, description: "Invoice 1",
19
19
  voucher_lines: [
20
- { account_number: "1500", amount: 512.0, booked_on: from_date + 2, description: "Item 1" },
21
- { account_number: "3100", amount: -512.0, booked_on: from_date + 2, description: "Item 1" },
20
+ { account_number: 1500, amount: 512.0, booked_on: from_date + 2, description: "Item 1" },
21
+ { account_number: 3100, amount: -512.0, booked_on: from_date + 2, description: "Item 1" },
22
22
  ]
23
23
  },
24
24
  {
25
25
  creditor: true, type: :payment, number: 2, booked_on: from_date + 365, description: "Payout 1",
26
26
  voucher_lines: [
27
- { account_number: "2400", amount: 256.0, booked_on: from_date + 365, description: "Payout line 1" },
28
- { account_number: "1970", amount: -256.0, booked_on: from_date + 365, description: "Payout line 2" },
27
+ { account_number: 2400, amount: 256.0, booked_on: from_date + 365, description: "Payout line 1" },
28
+ { account_number: 1970, amount: -256.0, booked_on: from_date + 365, description: "Payout line 2" },
29
29
  ]
30
30
  }
31
31
  ]
@@ -69,8 +69,8 @@ describe Sie::Document, "#render" do
69
69
  generated_on: generated_on,
70
70
  company_name: "Foocorp",
71
71
  financial_year_start_month: 1,
72
- balance_account_numbers: [ "1500", "2400" ],
73
- closing_account_numbers: [ "3100" ]
72
+ balance_account_numbers: [ 1500, 2400 ],
73
+ closing_account_numbers: [ 3100 ]
74
74
  )
75
75
  doc = Sie::Document.new(data_source)
76
76
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-27 00:00:00.000000000 Z
12
+ date: 2014-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: attr_extras
16
- requirement: &70219540379320 !ruby/object:Gem::Requirement
16
+ requirement: &70247794044260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70219540379320
24
+ version_requirements: *70247794044260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70219540378900 !ruby/object:Gem::Requirement
27
+ requirement: &70247794043840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70219540378900
35
+ version_requirements: *70247794043840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70219540378400 !ruby/object:Gem::Requirement
38
+ requirement: &70247794043340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70219540378400
46
+ version_requirements: *70247794043340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70219540377980 !ruby/object:Gem::Requirement
49
+ requirement: &70247794042920 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70219540377980
57
+ version_requirements: *70247794042920
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70219540377520 !ruby/object:Gem::Requirement
60
+ requirement: &70247794042460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70219540377520
68
+ version_requirements: *70247794042460
69
69
  description: SIE parser and generator
70
70
  email:
71
71
  - all@barsoom.se
@@ -96,6 +96,7 @@ files:
96
96
  - lib/sie/version.rb
97
97
  - script/bootstrap
98
98
  - script/refresh
99
+ - script/test
99
100
  - script/turbux_rspec
100
101
  - sie.gemspec
101
102
  - spec/fixtures/sie_file.se
@@ -122,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
123
  version: '0'
123
124
  segments:
124
125
  - 0
125
- hash: -4086731428764887794
126
+ hash: -3882600270749227957
126
127
  required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  none: false
128
129
  requirements:
@@ -131,10 +132,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  segments:
133
134
  - 0
134
- hash: -4086731428764887794
135
+ hash: -3882600270749227957
135
136
  requirements: []
136
137
  rubyforge_project:
137
- rubygems_version: 1.8.6
138
+ rubygems_version: 1.8.5
138
139
  signing_key:
139
140
  specification_version: 3
140
141
  summary: Parses and generates SIE files (http://sie.se/)