timetress 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+
9
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Knows about workdays and holidays, public and otherwise.
4
4
  Answers the age-old question _When is mothersday this year?_.
5
5
 
6
+ [![Build Status](https://secure.travis-ci.org/kytrinyx/timetress.png?branch=master)](http://travis-ci.org/kytrinyx/timetress)
7
+
6
8
  ## Installation
7
9
 
8
10
  Add this line to your application's Gemfile:
@@ -22,17 +24,17 @@ Or install it yourself as:
22
24
  ### Timetress knows about holidays
23
25
 
24
26
  ```
25
- Timetress.mothersday 2012
26
- => #<Date: 2012-02-12>
27
+ Timetress.christmas 2012
28
+ => #<Date: 2012-12-25>
27
29
  ```
28
30
 
29
31
  ```
30
- # In October of 2011
31
- Timetress.next_mothersday
32
- => #<Date: 2012-02-12>
32
+ # On New Year's Eve, 2011
33
+ Timetress.next_christmas
34
+ => #<Date: 2012-12-25>
33
35
  ```
34
36
 
35
- ### Public Holidays
37
+ ### Public Holidays (Norway only)
36
38
 
37
39
  > A public holiday, national holiday or legal holiday is a holiday generally established by law and is usually a non-working day during the year.
38
40
  > - Wikipedia
@@ -64,7 +66,7 @@ Timetress::Norway.nth_workday_after 1, Date.new(2012, 10, 25)
64
66
 
65
67
  ## Implemented holidays (Norway)
66
68
 
67
- Public holidays are emphasized.
69
+ Public holidays are emphasized below.
68
70
 
69
71
  * *New Year's Day*: January 1st.
70
72
  * Mothersday: Second Sunday in February.
@@ -3,6 +3,8 @@ module Timetress
3
3
 
4
4
  JANUARY = 1
5
5
  FEBRUARY = 2
6
+ MAY = 5
7
+ NOVEMBER = 11
6
8
  DECEMBER = 12
7
9
 
8
10
  def new_years_day(year)
@@ -53,16 +55,41 @@ module Timetress
53
55
  Date.new(year, DECEMBER, 26)
54
56
  end
55
57
 
58
+ def new_years_eve(year)
59
+ Date.new(year, DECEMBER, 31)
60
+ end
61
+
56
62
  def official_holidays(year)
57
- raise NotImplementedError
63
+ raise NotImplementedError.new localization_error_message
64
+ end
65
+
66
+ def mothersday(year)
67
+ raise NotImplementedError.new localization_error_message
68
+ end
69
+
70
+ def fathersday(year)
71
+ raise NotImplementedError.new localization_error_message
72
+ end
73
+
74
+ def labour_day(year)
75
+ raise NotImplementedError.new localization_error_message
76
+ end
77
+ alias_method :labor_day, :labour_day
78
+
79
+ def national_holiday(year)
80
+ raise NotImplementedError.new localization_error_message
58
81
  end
59
82
 
60
83
  private
61
84
 
85
+ def localization_error_message
86
+ "Different in different countries. Try the Norway module."
87
+ end
88
+
62
89
  def next_holiday(holiday, given_date)
63
90
  given_date ||= Date.today
64
91
 
65
- unless given_date.respond_to?(:to_datetime)
92
+ unless given_date.respond_to?(:asctime)
66
93
  raise ArgumentError.new("#{given_date.inspect} must be a date or time object")
67
94
  end
68
95
 
@@ -3,9 +3,6 @@ module Timetress
3
3
  module Holiday
4
4
  include Timetress::Holiday
5
5
 
6
- MAY = 5
7
- NOVEMBER = 11
8
-
9
6
  def mothersday(year)
10
7
  second_sunday_in(FEBRUARY, year)
11
8
  end
@@ -23,6 +20,16 @@ module Timetress
23
20
  Date.new(year, MAY, 17)
24
21
  end
25
22
 
23
+ def christmas(year)
24
+ raise AmbiguousHolidayError.new("Do you mean `christmas_eve` or `first_day_of_christmas`?")
25
+ end
26
+
27
+ def first_day_of_christmas(year)
28
+ Date.new(year, DECEMBER, 25)
29
+ end
30
+
31
+ alias_method :second_day_of_christmas, :boxing_day
32
+
26
33
  def official_holidays(year)
27
34
  [
28
35
  new_years_day(year),
@@ -35,7 +42,7 @@ module Timetress
35
42
  ascension(year),
36
43
  pentecost_sunday(year),
37
44
  pentecost_monday(year),
38
- christmas(year),
45
+ first_day_of_christmas(year),
39
46
  boxing_day(year)
40
47
  ]
41
48
  end
@@ -1,6 +1,8 @@
1
1
  require 'timetress/norway/holiday'
2
2
 
3
3
  module Timetress
4
+ class AmbiguousHolidayError < StandardError; end
5
+
4
6
  module Norway
5
7
  extend Timetress::Norway::Holiday
6
8
  extend Timetress::Workday
@@ -1,3 +1,3 @@
1
1
  module Timetress
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/spec/holiday_spec.rb CHANGED
@@ -82,9 +82,23 @@ describe Timetress::Holiday do
82
82
  end
83
83
  end
84
84
 
85
+ describe "New Year's Eve" do
86
+ it "is on Dec 31st" do
87
+ Timetress.new_years_eve(2011).should eq Date.new(2011, 12, 31)
88
+ end
89
+ end
90
+
85
91
  describe "official holidays" do
86
92
  it "must be implemented in subclass" do
87
- ->{ Timetress.official_holidays(2012) }.should raise_error
93
+ lambda { Timetress.official_holidays(2012) }.should raise_error
94
+ end
95
+ end
96
+
97
+ describe "it complains helpfully about" do
98
+ [:mothersday, :fathersday, :labor_day, :labour_day, :national_holiday].each do |holiday|
99
+ specify holiday.to_s do
100
+ lambda { Timetress.send(holiday, 2012) }.should raise_error /Norway/
101
+ end
88
102
  end
89
103
  end
90
104
 
@@ -109,9 +123,12 @@ describe Timetress::Holiday do
109
123
  Timetress::Norway.next_pi_day.should eq(Timetress::Norway.next_pi_day(Date.today))
110
124
  end
111
125
 
112
- it "complains if given a non-date argument" do
113
- ->{ Timetress::Norway.next_pi_day("a string") }.should raise_error(ArgumentError)
114
- ->{ Timetress::Norway.next_pi_day(1) }.should raise_error(ArgumentError)
126
+ it "rejects string input" do
127
+ lambda { Timetress::Norway.next_pi_day("a string") }.should raise_error(ArgumentError)
128
+ end
129
+
130
+ it "rejects integer input" do
131
+ lambda { Timetress::Norway.next_pi_day(1) }.should raise_error(ArgumentError)
115
132
  end
116
133
 
117
134
  end
@@ -72,4 +72,10 @@ describe Timetress::Norway do
72
72
  end
73
73
  end
74
74
 
75
+ describe "christmas" do
76
+ it "is ambiguous" do
77
+ lambda { Timetress::Norway.christmas(2012) }.should raise_error(Timetress::AmbiguousHolidayError)
78
+ end
79
+ end
80
+
75
81
  end
data/timetress.gemspec CHANGED
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec'
19
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70165893417640 !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: *70165893417640
14
25
  description: Answers the age-old question 'When is mothersday this year?'
15
26
  email:
16
27
  - katrina.owen@gmail.com
@@ -19,6 +30,7 @@ extensions: []
19
30
  extra_rdoc_files: []
20
31
  files:
21
32
  - .gitignore
33
+ - .travis.yml
22
34
  - Gemfile
23
35
  - LICENSE.txt
24
36
  - README.md
@@ -64,3 +76,4 @@ test_files:
64
76
  - spec/norway/holiday_spec.rb
65
77
  - spec/norway/workday_spec.rb
66
78
  - spec/workday_spec.rb
79
+ has_rdoc: