norwegian_holidays 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in norwegian_holidays.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Norwegian Holidays
2
+
3
+ A Norwegian holiday calendar.
4
+ Answers the age-old question: _When is mothersday this year?_
5
+
6
+ ## Implemented holidays
7
+
8
+ Mothersday: Second Sunday in February.
9
+ Fathersday: Second Sunday in November.
10
+ Valentines Day: February 14.
11
+ Christmas: December 24th (Norwegians only care about Christmas Eve, apparently).
12
+
13
+ ## Usage
14
+
15
+ NorwegianHolidays.christmas(2010)
16
+ => December 24, 2010
17
+
18
+ NorwegianHolidays.mothersday(2011)
19
+ => February 13, 2011
20
+
21
+ NorwegianHolidays.next_mothersday( Date.new(2011, 2, 7) )
22
+ => February 13, 2011
23
+
24
+ NorwegianHolidays.next_mothersday( Date.new(2011, 3, 14) )
25
+ => February 12, 2012
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,53 @@
1
+ require 'date'
2
+ require "norwegian_holidays/version"
3
+
4
+ module NorwegianHolidays
5
+
6
+ class << self
7
+
8
+ # In Norway the big day is Christmas Eve
9
+ def christmas(year)
10
+ Date.new(year, 12, 24)
11
+ end
12
+
13
+ def valentines_day(year)
14
+ Date.new(year, 2, 14)
15
+ end
16
+
17
+ def mothersday(year)
18
+ second_sunday_in(2, year)
19
+ end
20
+
21
+ def fathersday(year)
22
+ second_sunday_in(11, year)
23
+ end
24
+
25
+ def second_sunday_in(month, year)
26
+ second_week = Date.new(year, month, 8)
27
+ second_week + days_til_sunday(second_week)
28
+ end
29
+
30
+ def days_til_sunday(date)
31
+ (7 - date.wday) % 7
32
+ end
33
+
34
+ def method_missing(method, *args, &block)
35
+ if method.to_s =~ /^next_(.*)$/
36
+
37
+ given_date = args.first
38
+ holiday = $1
39
+
40
+ the_day = self.send(holiday.to_sym, given_date.year)
41
+
42
+ if the_day < given_date
43
+ the_day = self.send(holiday.to_sym, given_date.year + 1)
44
+ end
45
+
46
+ the_day
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module NorwegianHolidays
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "norwegian_holidays/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "norwegian_holidays"
7
+ s.version = NorwegianHolidays::VERSION
8
+ s.authors = ["Katrina Owen"]
9
+ s.email = ["katrina.owen@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A Norwegian holiday calendar.}
12
+ s.description = %q{A Norwegian holiday calendar. Answers the age-old question: "When is mothersday this year?"}
13
+
14
+ s.rubyforge_project = "norwegian_holidays"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "active_support"
24
+ s.add_development_dependency "i18n" #active support requires i18n but doesn't add dependency in bundle
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
@@ -0,0 +1,150 @@
1
+ require 'norwegian_holidays'
2
+ require 'active_support/core_ext'
3
+
4
+ describe NorwegianHolidays do
5
+ describe "#second_sunday_in(month, year)" do
6
+ it "works for a month beginning on Saturday" do
7
+ NorwegianHolidays.second_sunday_in(1, 2011).should eq(Date.new(2011, 1, 9))
8
+ end
9
+
10
+ it "works for a month beginning on Sunday" do
11
+ NorwegianHolidays.second_sunday_in(5, 2011).should eq(Date.new(2011, 5, 8))
12
+ end
13
+
14
+ it "works for a month beginning on Monday" do
15
+ NorwegianHolidays.second_sunday_in(8, 2011).should eq(Date.new(2011, 8, 14))
16
+ end
17
+ end
18
+
19
+ describe "#christmas(year)" do
20
+ it "is on Christmas Eve" do
21
+ NorwegianHolidays.christmas(2011).should eq(Date.new(2011, 12, 24))
22
+ end
23
+ end
24
+
25
+ describe "#valentines_day(year)" do
26
+ it "is on Feb 14th" do
27
+ NorwegianHolidays.valentines_day(2011).should eq(Date.new(2011, 2, 14))
28
+ end
29
+ end
30
+
31
+ describe "#mothersday(year)" do
32
+ it "is on the second Sunday of February" do
33
+ NorwegianHolidays.mothersday(2010).should eq(Date.new(2010, 2, 14))
34
+ end
35
+ end
36
+
37
+ describe "#fathersday(year)" do
38
+ it "is on the second Sunday of November" do
39
+ NorwegianHolidays.fathersday(2010).should eq(Date.new(2010, 11, 14))
40
+ end
41
+ end
42
+
43
+ describe "#next_christmas" do
44
+ let(:christmas) { Date.new(2011, 12, 24) }
45
+
46
+ it "is on Dec 24th" do
47
+ NorwegianHolidays.next_christmas(christmas - 1.day).should eq(christmas)
48
+ end
49
+
50
+ it "is this year if today is Christmas Eve" do
51
+ NorwegianHolidays.next_christmas(christmas).should eq(christmas)
52
+ end
53
+
54
+ it "is next year if it's already passed" do
55
+ NorwegianHolidays.next_christmas(christmas + 1.day).should eq(christmas + 1.year)
56
+ end
57
+ end
58
+
59
+ describe "#next_valentines_day" do
60
+ let(:valentines_day) { Date.new(2011, 2, 14) }
61
+
62
+ it "is on Feb 14th" do
63
+ NorwegianHolidays.next_valentines_day(valentines_day - 1.day).should eq(valentines_day)
64
+ end
65
+
66
+ it "is this year if today is valentines day" do
67
+ NorwegianHolidays.next_valentines_day(valentines_day).should eq(valentines_day)
68
+ end
69
+
70
+ it "is next year if it's already passed" do
71
+ NorwegianHolidays.next_valentines_day(valentines_day + 1.day).should eq(valentines_day + 1.year)
72
+ end
73
+ end
74
+
75
+ describe "#next_mothersday" do
76
+ let(:mothersday_2010) { Date.new(2010, 2, 14) }
77
+ let(:mothersday_2011) { Date.new(2011, 2, 13) }
78
+ let(:mothersday_2012) { Date.new(2012, 2, 12) }
79
+
80
+ context "(sanity check) correct in" do
81
+ specify "2010" do
82
+ NorwegianHolidays.next_mothersday( Date.new(2010, 1, 1) ).should eq(mothersday_2010)
83
+ end
84
+
85
+ specify "2011" do
86
+ NorwegianHolidays.next_mothersday( Date.new(2011, 1, 1) ).should eq(mothersday_2011)
87
+ end
88
+
89
+ specify "2012" do
90
+ NorwegianHolidays.next_mothersday( Date.new(2012, 1, 1) ).should eq(mothersday_2012)
91
+ end
92
+ end
93
+
94
+ context "on mothersday" do
95
+ it "is this year" do
96
+ NorwegianHolidays.next_mothersday(mothersday_2010).should eq(mothersday_2010)
97
+ end
98
+ end
99
+
100
+ context "before mothersday" do
101
+ it "is this year" do
102
+ NorwegianHolidays.next_mothersday(mothersday_2010 - 1.day).should eq(mothersday_2010)
103
+ end
104
+ end
105
+
106
+ context "after mothersday" do
107
+ it "is next year" do
108
+ NorwegianHolidays.next_mothersday(mothersday_2010 + 1.day).should eq(mothersday_2011)
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "#next_fathersday" do
114
+ let(:fathersday_2010) { Date.new(2010, 11, 14) }
115
+ let(:fathersday_2011) { Date.new(2011, 11, 13) }
116
+ let(:fathersday_2012) { Date.new(2012, 11, 11) }
117
+
118
+ context "(sanity check) correct in" do
119
+ specify "2010" do
120
+ NorwegianHolidays.next_fathersday( Date.new(2010, 1, 1) ).should eq(fathersday_2010)
121
+ end
122
+
123
+ specify "2011" do
124
+ NorwegianHolidays.next_fathersday( Date.new(2011, 1, 1) ).should eq(fathersday_2011)
125
+ end
126
+
127
+ specify "2012" do
128
+ NorwegianHolidays.next_fathersday( Date.new(2012, 1, 1) ).should eq(fathersday_2012)
129
+ end
130
+ end
131
+
132
+ context "on fathersday" do
133
+ it "is this year" do
134
+ NorwegianHolidays.next_fathersday(fathersday_2010).should eq(fathersday_2010)
135
+ end
136
+ end
137
+
138
+ context "before fathersday" do
139
+ it "is this year" do
140
+ NorwegianHolidays.next_fathersday(fathersday_2010 - 1.day).should eq(fathersday_2010)
141
+ end
142
+ end
143
+
144
+ context "after fathersday" do
145
+ it "is next year" do
146
+ NorwegianHolidays.next_fathersday(fathersday_2010 + 1.day).should eq(fathersday_2011)
147
+ end
148
+ end
149
+ end
150
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norwegian_holidays
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Katrina Owen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70138570566060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70138570566060
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_support
27
+ requirement: &70138570565640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70138570565640
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ requirement: &70138570565220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70138570565220
47
+ description: ! 'A Norwegian holiday calendar. Answers the age-old question: "When
48
+ is mothersday this year?"'
49
+ email:
50
+ - katrina.owen@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - README.md
59
+ - Rakefile
60
+ - lib/norwegian_holidays.rb
61
+ - lib/norwegian_holidays/version.rb
62
+ - norwegian_holidays.gemspec
63
+ - spec/norwegian_holidays_spec.rb
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: norwegian_holidays
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A Norwegian holiday calendar.
88
+ test_files: []