fyuk 0.6.3 → 0.6.4
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/Gemfile +3 -0
- data/Gemfile.lock +4 -0
- data/VERSION +1 -1
- data/fyuk.gemspec +8 -2
- data/lib/uk_financial_year.rb +21 -25
- data/spec/uk_financial_year_spec.rb +1 -0
- metadata +35 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (3.0.0)
|
4
5
|
columnize (0.3.6)
|
5
6
|
debugger (1.1.3)
|
6
7
|
columnize (>= 0.3.1)
|
@@ -11,6 +12,7 @@ GEM
|
|
11
12
|
debugger-ruby_core_source (1.1.2)
|
12
13
|
diff-lcs (1.1.3)
|
13
14
|
git (1.2.5)
|
15
|
+
i18n (0.6.1)
|
14
16
|
jeweler (1.6.4)
|
15
17
|
bundler (~> 1.0)
|
16
18
|
git (>= 1.2.5)
|
@@ -32,8 +34,10 @@ PLATFORMS
|
|
32
34
|
ruby
|
33
35
|
|
34
36
|
DEPENDENCIES
|
37
|
+
activesupport
|
35
38
|
bundler (~> 1.0.0)
|
36
39
|
debugger
|
40
|
+
i18n
|
37
41
|
jeweler (~> 1.6.4)
|
38
42
|
rcov
|
39
43
|
rspec (~> 2.9.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.4
|
data/fyuk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fyuk"
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nigel Lowry"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-05"
|
13
13
|
s.description = "Small library with methods for finding the financial or fiscal year for a particular date and suchlike. Used by Hubo https://hubo.herokuapp.com/"
|
14
14
|
s.email = "nigel-lowry@ultra.eclipse.co.uk"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,6 +41,8 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.specification_version = 3
|
42
42
|
|
43
43
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
44
46
|
s.add_development_dependency(%q<rspec>, ["~> 2.9.0"])
|
45
47
|
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
46
48
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -48,6 +50,8 @@ Gem::Specification.new do |s|
|
|
48
50
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
51
|
s.add_development_dependency(%q<debugger>, [">= 0"])
|
50
52
|
else
|
53
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
54
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
51
55
|
s.add_dependency(%q<rspec>, ["~> 2.9.0"])
|
52
56
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
53
57
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -56,6 +60,8 @@ Gem::Specification.new do |s|
|
|
56
60
|
s.add_dependency(%q<debugger>, [">= 0"])
|
57
61
|
end
|
58
62
|
else
|
63
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
64
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
59
65
|
s.add_dependency(%q<rspec>, ["~> 2.9.0"])
|
60
66
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
61
67
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
data/lib/uk_financial_year.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/all'
|
2
2
|
|
3
3
|
# Makes working with the UK financial or fiscal year easier.
|
4
4
|
class UkFinancialYear
|
@@ -19,7 +19,7 @@ class UkFinancialYear
|
|
19
19
|
# @return [String] representation in the form of the first year as four
|
20
20
|
# digits, a '/', then the last year as two digits
|
21
21
|
def to_s
|
22
|
-
"#{first_day.year}/#{last_day.year.to_s
|
22
|
+
"#{first_day.year}/#{last_day.year.to_s.from 2}"
|
23
23
|
end
|
24
24
|
|
25
25
|
# creates a new UkFinancialYear from a string in the form '2000/01'
|
@@ -29,16 +29,20 @@ class UkFinancialYear
|
|
29
29
|
# @raise [RuntimeError] if the string cannot be parsed to a financial year
|
30
30
|
# @return [UkFinancialYear] the financial year specified by the string
|
31
31
|
def UkFinancialYear.from_s s
|
32
|
+
check_format s
|
33
|
+
new(Date.new s.to(3).to_i, 4, 6)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.check_format s
|
32
37
|
if /^(?<year1>\d{4})\/(?<year2>\d{2})$/ =~ s
|
33
38
|
year1 = year1.to_i
|
34
39
|
year1_century = year1 / 100
|
35
40
|
year2_century = year1 % 100 == 99 ? year1_century + 1 : year1_century
|
36
41
|
year2 = year2_century * 100 + year2.to_i
|
37
|
-
raise %{"#{year1}" and "#{year2}" are not consecutive years} unless
|
38
|
-
|
42
|
+
raise %{"#{year1}" and "#{year2}" are not consecutive years} unless year1 + 1 == year2
|
43
|
+
else
|
44
|
+
raise %{"#{s}" does not match FY string format}
|
39
45
|
end
|
40
|
-
|
41
|
-
raise %{"#{s}" does not match FY string format}
|
42
46
|
end
|
43
47
|
|
44
48
|
# returns the date of the first day of the financial year
|
@@ -73,21 +77,21 @@ class UkFinancialYear
|
|
73
77
|
end
|
74
78
|
|
75
79
|
def adjacent? other_financial_year
|
76
|
-
|
80
|
+
other_financial_year.last_day.tomorrow == self.first_day or other_financial_year.first_day.yesterday == self.last_day
|
77
81
|
end
|
78
82
|
|
79
83
|
# tells if the given date or financial year is before this one
|
80
84
|
# @param [Date] date_or_fy date or financial year to check
|
81
85
|
# @return [Boolean] to indicate if this financial year is before
|
82
86
|
def before? date_or_fy
|
83
|
-
self.first_day
|
87
|
+
self.first_day < date_to_compare(date_or_fy)
|
84
88
|
end
|
85
89
|
|
86
90
|
# tells if the given date or financial year is after this one
|
87
|
-
# @param (see
|
91
|
+
# @param (see UkFinancialYear#before?)
|
88
92
|
# @return [Boolean] to indicate if this financial year is after
|
89
93
|
def after? date_or_fy
|
90
|
-
self.first_day
|
94
|
+
self.first_day > date_to_compare(date_or_fy)
|
91
95
|
end
|
92
96
|
|
93
97
|
# returns the period before this date in the financial year
|
@@ -95,8 +99,8 @@ class UkFinancialYear
|
|
95
99
|
# @return [Range<Date>] the period before this date in the the
|
96
100
|
# financial year
|
97
101
|
def period_before date
|
98
|
-
raise "#{date} is before FY #{to_s}" if date < first_day
|
99
|
-
raise "#{date} is after FY #{to_s}" if date > last_day
|
102
|
+
raise "#{date} is before FY #{to_s} which starts on #{first_day}" if date < first_day
|
103
|
+
raise "#{date} is after FY #{to_s} which ends on #{last_day}" if date > last_day
|
100
104
|
|
101
105
|
first_day...date
|
102
106
|
end
|
@@ -112,22 +116,14 @@ class UkFinancialYear
|
|
112
116
|
end
|
113
117
|
|
114
118
|
private
|
115
|
-
def date_to_compare other
|
116
|
-
if other.is_a?(Date) then other else other.first_day end
|
117
|
-
end
|
118
119
|
|
119
120
|
def start_date date
|
120
|
-
swap_date_that_year =
|
121
|
-
|
121
|
+
swap_date_that_year = date.change day: 6, month: 4
|
122
|
+
date < swap_date_that_year ? swap_date_that_year.prev_year : swap_date_that_year
|
122
123
|
end
|
123
|
-
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
125
|
+
def date_to_compare other
|
126
|
+
other.is_a?(Date) ? other : other.first_day
|
127
|
+
end
|
129
128
|
|
130
|
-
def after? other
|
131
|
-
self > other
|
132
|
-
end
|
133
129
|
end
|
@@ -50,6 +50,7 @@ describe UkFinancialYear do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#from_s" do
|
53
|
+
specify { UkFinancialYear.from_s('1997/98').to_s.should == '1997/98' }
|
53
54
|
specify { UkFinancialYear.from_s('1998/99').to_s.should == '1998/99' }
|
54
55
|
specify { UkFinancialYear.from_s('1999/00').to_s.should == '1999/00' }
|
55
56
|
specify { UkFinancialYear.from_s('2000/01').to_s.should == '2000/01' }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fyuk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: i18n
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
14
46
|
- !ruby/object:Gem::Dependency
|
15
47
|
name: rspec
|
16
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
176
|
version: '0'
|
145
177
|
segments:
|
146
178
|
- 0
|
147
|
-
hash:
|
179
|
+
hash: -695263215771451728
|
148
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
181
|
none: false
|
150
182
|
requirements:
|