fyuk 0.0.1 → 0.1.0

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fyuk"
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
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"]
@@ -1,44 +1,68 @@
1
1
  require 'date'
2
2
 
3
+ # Makes working with the UK financial or fiscal year easier.
3
4
  class UkFinancialYear
4
5
  include Comparable
5
6
 
7
+ # creates a new UkFinancialYear as the financial year which
8
+ # includes the given date
9
+ # @param [Date] date the date to create a financial year for
10
+ # @return [UkFinancialYear] the financial year which covers the date
6
11
  def initialize date
7
12
  start_date = start_date date
8
13
  @range = start_date...start_date.next_year
9
14
  end
10
15
 
16
+ # creates a new UkFinancialYear from a string in the form '2000/01'
17
+ # @param [String] s the two years of the financial year in the form
18
+ # of the first year as four digits, a '/', then the last year as
19
+ # two digits
20
+ # @return [UkFinancialYear] the financial year specified by the string
11
21
  def UkFinancialYear.from_s s
12
- if /^20(?<year1>\d{2})\/(?<year2>\d{2})$/ =~ s
13
- year1 = 2000 + year1.to_i
14
- year2 = 2000 + year2.to_i
15
- raise %{"#{year1}" and "#{year2}" are not consecutive years} unless year1 + 1 == year2
16
- return new(Date.parse "6 Apr #{year1}")
22
+ if /^(?<year1>\d{4})\/(?<year2>\d{2})$/ =~ s
23
+ year1 = year1.to_i
24
+ year1_century = year1 / 100
25
+ year2_century = year1 % 100 == 99 ? year1_century + 1 : year1_century
26
+ year2 = year2_century * 100 + year2.to_i
27
+ raise %{"#{year1}" and "#{year2}" are not consecutive years} unless year2 == year1 + 1
28
+ return new(Date.new year1, 4, 6)
17
29
  end
18
30
 
19
31
  raise %{"#{s}" does not match FY string format}
20
32
  end
21
33
 
34
+ # returns the date of the first day of the financial year
35
+ # @return [Date] the first day
22
36
  def first_day
23
37
  @range.min
24
38
  end
25
39
 
40
+ # returns the date of the last day of the financial year
41
+ # @return [Date] the last day
26
42
  def last_day
27
43
  @range.max
28
44
  end
29
45
 
46
+ # tells if the financial year includes the given date
47
+ # @param [Date] date the date to check
48
+ # @return [Boolean] to indicate if the date is within the financial year
30
49
  def include? date
31
50
  @range.include? date
32
51
  end
33
52
 
53
+ # returns string representation of the financial year in the form '2000/01'
54
+ # @return [String] representation in the form of the first year as four
55
+ # digits, a '/', then the last year as two digits
34
56
  def to_s
35
57
  "#{self.first_day.year}/#{self.last_day.year.to_s[-2..-1]}"
36
58
  end
37
59
 
60
+ # equality method
38
61
  def ==(other)
39
62
  self.first_day == other.first_day
40
63
  end
41
64
 
65
+ # lesser financial years are those which occur first in time
42
66
  def <=>(other)
43
67
  self.first_day <=> other.first_day
44
68
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'date'
3
2
 
4
3
  describe UkFinancialYear do
5
4
  describe "#first_day" do
@@ -90,6 +89,18 @@ describe UkFinancialYear do
90
89
  fy.last_day.should == Date.parse('5 Apr 2003')
91
90
  end
92
91
 
92
+ it "is 1998/99 for '1998/99'" do
93
+ fy = UkFinancialYear.from_s('1998/99')
94
+ fy.first_day.should == Date.parse('6 Apr 1998')
95
+ fy.last_day.should == Date.parse('5 Apr 1999')
96
+ end
97
+
98
+ it "is 1999/00 for '1999/00'" do
99
+ fy = UkFinancialYear.from_s('1999/00')
100
+ fy.first_day.should == Date.parse('6 Apr 1999')
101
+ fy.last_day.should == Date.parse('5 Apr 2000')
102
+ end
103
+
93
104
  it "raises error if years not consecutive" do
94
105
  expect {
95
106
  UkFinancialYear.from_s '2002/04'
@@ -107,14 +118,6 @@ describe UkFinancialYear do
107
118
  /"20001\/02" does not match FY string format/
108
119
  )
109
120
  end
110
-
111
- it "raises error on 20th century FY" do
112
- expect {
113
- UkFinancialYear.from_s '1998/99'
114
- }.to raise_error(
115
- RuntimeError
116
- )
117
- end
118
121
  end
119
122
 
120
123
  describe "object comparison" do
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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70355023697860 !ruby/object:Gem::Requirement
16
+ requirement: &70191725721420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70355023697860
24
+ version_requirements: *70191725721420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &70355023697340 !ruby/object:Gem::Requirement
27
+ requirement: &70191725720840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70355023697340
35
+ version_requirements: *70191725720840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70355023696760 !ruby/object:Gem::Requirement
38
+ requirement: &70191725720260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70355023696760
46
+ version_requirements: *70191725720260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70355023696180 !ruby/object:Gem::Requirement
49
+ requirement: &70191725719640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70355023696180
57
+ version_requirements: *70191725719640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70355023695600 !ruby/object:Gem::Requirement
60
+ requirement: &70191725719100 !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: *70355023695600
68
+ version_requirements: *70191725719100
69
69
  description: Small library with methods for finding the financial or fiscal year for
70
70
  a particular date and suchlike
71
71
  email: nigel-lowry@ultra.eclipse.co.uk
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: -2520681571740634187
105
+ hash: -881557483887040957
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements: