us_bank_holidays 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55df8b485e62ef28d7d1872ff78e21a807e241e0
4
- data.tar.gz: 0c36413d6b45bb274e3c70a1929c6a517ab3af0e
3
+ metadata.gz: a4921197ea42b26e8e08bf2f4059f034c805e214
4
+ data.tar.gz: d40a2bbb91cce5c533a7f0056e833ba9bf09ebfd
5
5
  SHA512:
6
- metadata.gz: 2153d108279fd2296d312274210153bf10ee38c50d1239baf4dc9e5ae3c1303d01fed80801ea77268419bcd6ee0f8ab3e5eb2703f5fab3b8bf9c22e15039ec40
7
- data.tar.gz: 8ab9877ee8d665d75ba9385fde4aaa05ed186db5bdaa900cb5f24ba5c8258722d884dcd9e815515b9a1d6fd6698682bf614a189d147c029def5a3f632b9c2956
6
+ metadata.gz: b90aab66fb070972ce928c186233c2ca82066b371691b728cec75b8e4c94a7f9c6c5b09dd4e7bdad9dd37ff4c907f223b789c58acfb299801786801ba92945b7
7
+ data.tar.gz: 4a944a80069321f13677993dc3a3ff4b386b8dc93c740d657f0b6aa012ae98c8679a5dbed74094b8e6e1f6a2689692cb7e832f60019ee86e1547b40db5759569
@@ -19,35 +19,8 @@ module UsBankHolidays
19
19
  def initialize(year)
20
20
  @year = year
21
21
 
22
- # First of the year, rolls either forward or back.
23
- @new_years_day = roll_nominal(Date.new(year, 1, 1))
24
-
25
- # Third Monday of January
26
- @mlk_day = ::UsBankHolidays::Month.new(year, 1).mondays[2]
27
-
28
- # Third Monday of February
29
- @washingtons_birthday = ::UsBankHolidays::Month.new(year, 2).mondays[2]
30
-
31
- # Last Monday of May
32
- @memorial_day = ::UsBankHolidays::Month.new(year, 5).mondays.last
33
-
34
- # 4'th of July
35
- @independence_day = roll_nominal(Date.new(year, 7, 4))
36
-
37
- # First Monday of September
38
- @labor_day = ::UsBankHolidays::Month.new(year, 9).mondays.first
39
-
40
- # Second Monday of October
41
- @columbus_day = ::UsBankHolidays::Month.new(year, 10).mondays[1]
42
-
43
- # November 11
44
- @veterans_day = roll_nominal(Date.new(year, 11, 11))
45
-
46
- # Fourth Thursday of November
47
- @thanksgiving = ::UsBankHolidays::Month.new(year, 11).thursdays[3]
48
-
49
- # December 25
50
- @christmas = roll_nominal(Date.new(year, 12, 25))
22
+ init_fixed_holidays
23
+ init_rolled_holidays
51
24
 
52
25
  end
53
26
 
@@ -74,20 +47,78 @@ module UsBankHolidays
74
47
  end
75
48
  end
76
49
 
77
- # Figures out where to roll the given nominal date. If it's a Saturday, assumes
78
- # it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
79
- # just returns self.
80
- def roll_nominal(nominal)
81
- if nominal.saturday?
82
- nominal - 1
83
- elsif nominal.sunday?
84
- nominal + 1
85
- else
86
- nominal
50
+ {
51
+ :january => 1,
52
+ :february => 2,
53
+ :march => 3,
54
+ :april => 4,
55
+ :may => 5,
56
+ :june => 6,
57
+ :july => 7,
58
+ :august => 8,
59
+ :september => 9,
60
+ :october => 10,
61
+ :november => 11,
62
+ :december => 12
63
+ }.each do |month_name, month_index|
64
+ # Create a method that returns an instance of UsBankHolidays::Month for
65
+ # the needed month
66
+ define_method(month_name) do
67
+ ::UsBankHolidays::Month.new(year, month_index)
87
68
  end
88
69
  end
89
- private :roll_nominal
70
+
71
+ private
72
+
73
+ # These holidays are always fixed
74
+ def init_fixed_holidays
75
+ # Third Monday of January
76
+ @mlk_day = january.mondays[2]
77
+
78
+ # Third Monday of February
79
+ @washingtons_birthday = february.mondays[2]
80
+
81
+ # Last Monday of May
82
+ @memorial_day = may.mondays.last
83
+
84
+ # First Monday of September
85
+ @labor_day = september.mondays.first
86
+
87
+ # Second Monday of October
88
+ @columbus_day = october.mondays[1]
89
+
90
+ # Fourth Thursday of November
91
+ @thanksgiving = november.thursdays[3]
92
+ end
93
+
94
+ # These holidays are potentially rolled if they come on a weekend.
95
+ def init_rolled_holidays
96
+ # First of the year, rolls either forward or back.
97
+ @new_years_day = roll_nominal(Date.new(year, 1, 1))
98
+
99
+ # 4'th of July
100
+ @independence_day = roll_nominal(Date.new(year, 7, 4))
101
+
102
+ # November 11
103
+ @veterans_day = roll_nominal(Date.new(year, 11, 11))
104
+
105
+ # December 25
106
+ @christmas = roll_nominal(Date.new(year, 12, 25))
107
+ end
108
+
109
+ # Figures out where to roll the given nominal date. If it's a Saturday, assumes
110
+ # it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
111
+ # just returns self.
112
+ def roll_nominal(nominal)
113
+ if nominal.saturday?
114
+ nominal - 1
115
+ elsif nominal.sunday?
116
+ nominal + 1
117
+ else
118
+ nominal
119
+ end
120
+ end
90
121
 
91
122
  end
92
123
 
93
- end
124
+ end
@@ -1,3 +1,3 @@
1
1
  module UsBankHolidays
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -20,4 +20,30 @@ describe UsBankHolidays::HolidayYear do
20
20
  it 'should declare Dec. 31 a bank holiday if it falls on a Friday' do
21
21
  UsBankHolidays::HolidayYear.new(2021).bank_holidays.last.should == Date.new(2021, 12, 31)
22
22
  end
23
- end
23
+
24
+ context 'Months' do
25
+ let(:year) { UsBankHolidays::HolidayYear.new(2014) }
26
+
27
+ {
28
+ :january => 1,
29
+ :february => 2,
30
+ :march => 3,
31
+ :april => 4,
32
+ :may => 5,
33
+ :june => 6,
34
+ :july => 7,
35
+ :august => 8,
36
+ :september => 9,
37
+ :october => 10,
38
+ :november => 11,
39
+ :december => 12
40
+ }.each do |month_name, month_index|
41
+ it "should respond to '#{month_name}' and return the right month" do
42
+ year.respond_to?(month_name).should be_true
43
+ month = year.send(month_name)
44
+ month.year.should == 2014
45
+ month.month.should == month_index
46
+ end
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: us_bank_holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Shagall
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ~>
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.3'
25
- prerelease: false
26
- type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
29
  requirement: !ruby/object:Gem::Requirement
35
30
  requirements:
36
31
  - - '>='
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
39
- prerelease: false
40
34
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
35
+ prerelease: false
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
38
  - - '>='
46
39
  - !ruby/object:Gem::Version
47
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
44
  requirements:
50
45
  - - '>='
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
- prerelease: false
54
48
  type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: simplecov
49
+ prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
62
57
  requirement: !ruby/object:Gem::Requirement
63
58
  requirements:
64
59
  - - '>='
65
60
  - !ruby/object:Gem::Version
66
61
  version: '0'
67
- prerelease: false
68
62
  type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
69
  description: Simplify working with US bank holidays.
70
70
  email:
71
71
  - arthur.shagall@gmail.com
@@ -91,7 +91,7 @@ homepage: https://github.com/albertosaurus/us_bank_holidays
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -106,9 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.2.1
111
- signing_key:
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Patches Date to add methods to make dealing with US bank holidays simpler.
114
114
  test_files: