holidate 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/holidate.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'holidate'
5
- s.version = '0.0.4'
5
+ s.version = '1.0.0'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'Holiday Dates'
8
8
  s.description = 'A simple gem that returns Date objects for holidays'
data/lib/holidate.rb CHANGED
@@ -1,71 +1,73 @@
1
1
  require 'date'
2
2
 
3
3
  class Holidate
4
- def self.find(nth_, wday_, month_, year_=Date.today.year)
5
- nth = nth_int(nth_)
6
- wday = wday_int(wday_)
7
- month = month_int(month_)
8
- year = year_int(year_)
9
- if nth > 0
10
- Date.new(year, month, (1 + (nth - 1) * 7 + (wday - Date.new(year, month, 1).wday) % 7))
11
- else
12
- days_in_month = ((Date.new(year, month) >> 1) - 1).day
13
- Date.new(year, month, (days_in_month - (-nth - 1) * 7 - (Date.new(year, month, days_in_month).wday - wday) % 7))
4
+ class << self
5
+
6
+ undef_method(:new)
7
+
8
+ def find(nth_, wday_, month_, year_=Date.today.year)
9
+ nth = nth_int(nth_)
10
+ wday = wday_int(wday_)
11
+ month = month_int(month_)
12
+ year = year_int(year_)
13
+ if nth > 0
14
+ Date.new(year, month, (1 + (nth - 1) * 7 + (wday - Date.new(year, month, 1).wday) % 7))
15
+ else
16
+ days_in_month = ((Date.new(year, month) >> 1) - 1).day
17
+ Date.new(year, month, (days_in_month - (-nth - 1) * 7 - (Date.new(year, month, days_in_month).wday - wday) % 7))
18
+ end
14
19
  end
15
- end
16
- singleton_class.send(:alias_method, :find_day, :find)
17
20
 
18
- def self.new_years_day(year=Date.today.year)
19
- Date.new(year, 1, 1)
20
- end
21
- singleton_class.send(:alias_method, :new_year, :new_years_day)
21
+ def new_years_day(year=Date.today.year)
22
+ Date.new(year, 1, 1)
23
+ end
24
+ alias_method(:new_year, :new_years_day)
22
25
 
23
- def self.martin_luther_king_jr_day(year=Date.today.year)
24
- find('third', 'monday', 'january', year)
25
- end
26
- singleton_class.send(:alias_method, :mlk, :martin_luther_king_jr_day)
26
+ def martin_luther_king_jr_day(year=Date.today.year)
27
+ find('third', 'monday', 'january', year)
28
+ end
29
+ alias_method(:mlk, :martin_luther_king_jr_day)
27
30
 
28
- def self.washingtons_birthday(year=Date.today.year)
29
- find('third', 'monday', 'february', year)
30
- end
31
- singleton_class.send(:alias_method, :washington, :washingtons_birthday)
31
+ def washingtons_birthday(year=Date.today.year)
32
+ find('third', 'monday', 'february', year)
33
+ end
34
+ alias_method(:washington, :washingtons_birthday)
32
35
 
33
- def self.memorial_day(year=Date.today.year)
34
- find('last', 'monday', 'may', year)
35
- end
36
- singleton_class.send(:alias_method, :memorial, :memorial_day)
36
+ def memorial_day(year=Date.today.year)
37
+ find('last', 'monday', 'may', year)
38
+ end
39
+ alias_method(:memorial, :memorial_day)
37
40
 
38
- def self.independence_day(year=Date.today.year)
39
- Date.new(year, 7, 4)
40
- end
41
- singleton_class.send(:alias_method, :july_4, :independence_day)
41
+ def independence_day(year=Date.today.year)
42
+ Date.new(year, 7, 4)
43
+ end
44
+ alias_method(:july_4, :independence_day)
42
45
 
43
- def self.labor_day(year=Date.today.year)
44
- find('first', 'monday', 'september', year)
45
- end
46
- singleton_class.send(:alias_method, :labor, :labor_day)
46
+ def labor_day(year=Date.today.year)
47
+ find('first', 'monday', 'september', year)
48
+ end
49
+ alias_method(:labor, :labor_day)
47
50
 
48
- def self.columbus_day(year=Date.today.year)
49
- find('second', 'monday', 'october', year)
50
- end
51
- singleton_class.send(:alias_method, :columbus, :columbus_day)
51
+ def columbus_day(year=Date.today.year)
52
+ find('second', 'monday', 'october', year)
53
+ end
54
+ alias_method(:columbus, :columbus_day)
52
55
 
53
- def self.veterans_day(year=Date.today.year)
54
- Date.new(year, 11, 11)
55
- end
56
- singleton_class.send(:alias_method, :veteran, :veterans_day)
56
+ def veterans_day(year=Date.today.year)
57
+ Date.new(year, 11, 11)
58
+ end
59
+ alias_method(:veteran, :veterans_day)
57
60
 
58
- def self.thanksgiving_day(year=Date.today.year)
59
- find('fourth', 'thursday', 'november', year)
60
- end
61
- singleton_class.send(:alias_method, :thanksgiving, :thanksgiving_day)
61
+ def thanksgiving_day(year=Date.today.year)
62
+ find('fourth', 'thursday', 'november', year)
63
+ end
64
+ alias_method(:thanksgiving, :thanksgiving_day)
62
65
 
63
- def self.christmas_day(year=Date.today.year)
64
- Date.new(year, 12, 25)
65
- end
66
- singleton_class.send(:alias_method, :xmas, :christmas_day)
66
+ def christmas_day(year=Date.today.year)
67
+ Date.new(year, 12, 25)
68
+ end
69
+ alias_method(:xmas, :christmas_day)
67
70
 
68
- class << self
69
71
  protected
70
72
 
71
73
  def nth_int(nth_)
@@ -5,6 +5,10 @@ require 'holidate'
5
5
 
6
6
  describe Holidate do
7
7
 
8
+ it "doesn't respond to ::new" do
9
+ Holidate.respond_to?(:new).must_equal false
10
+ end
11
+
8
12
  describe '::new_years_day' do
9
13
  it "finds New Year's Day" do
10
14
  Holidate.new_year(2014).must_equal Date.new(2014, 1, 1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holidate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-07 00:00:00.000000000 Z
12
+ date: 2015-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler