holidays 1.0.8 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +19 -0
  4. data/Rakefile +1 -2
  5. data/data/au.yaml +81 -1
  6. data/data/ca.yaml +40 -3
  7. data/data/cr.yaml +63 -0
  8. data/data/federal_reserve.yaml +4 -28
  9. data/data/fedex.yaml +56 -0
  10. data/data/index.yaml +2 -0
  11. data/data/jp.yaml +8 -1
  12. data/lib/holidays.rb +219 -0
  13. data/lib/holidays/MANIFEST +2 -0
  14. data/lib/holidays/ar.rb +1 -1
  15. data/lib/holidays/at.rb +1 -1
  16. data/lib/holidays/au.rb +27 -4
  17. data/lib/holidays/be.rb +1 -1
  18. data/lib/holidays/br.rb +1 -1
  19. data/lib/holidays/ca.rb +6 -3
  20. data/lib/holidays/ch.rb +1 -1
  21. data/lib/holidays/cl.rb +1 -1
  22. data/lib/holidays/cr.rb +39 -0
  23. data/lib/holidays/cz.rb +1 -1
  24. data/lib/holidays/de.rb +2 -2
  25. data/lib/holidays/dk.rb +1 -1
  26. data/lib/holidays/ecb_target.rb +1 -1
  27. data/lib/holidays/el.rb +1 -1
  28. data/lib/holidays/es.rb +1 -1
  29. data/lib/holidays/europe.rb +75 -32
  30. data/lib/holidays/fed_ex.rb +36 -0
  31. data/lib/holidays/federal_reserve.rb +5 -8
  32. data/lib/holidays/fi.rb +1 -1
  33. data/lib/holidays/fr.rb +1 -1
  34. data/lib/holidays/gb.rb +1 -1
  35. data/lib/holidays/hr.rb +1 -1
  36. data/lib/holidays/hu.rb +1 -1
  37. data/lib/holidays/ie.rb +1 -1
  38. data/lib/holidays/is.rb +1 -1
  39. data/lib/holidays/it.rb +1 -1
  40. data/lib/holidays/jp.rb +3 -2
  41. data/lib/holidays/li.rb +1 -1
  42. data/lib/holidays/lt.rb +1 -1
  43. data/lib/holidays/ma.rb +1 -1
  44. data/lib/holidays/mx.rb +1 -1
  45. data/lib/holidays/nerc.rb +1 -1
  46. data/lib/holidays/nl.rb +1 -1
  47. data/lib/holidays/no.rb +1 -1
  48. data/lib/holidays/north_america.rb +8 -5
  49. data/lib/holidays/nyse.rb +1 -1
  50. data/lib/holidays/nz.rb +1 -1
  51. data/lib/holidays/pl.rb +1 -1
  52. data/lib/holidays/pt.rb +1 -1
  53. data/lib/holidays/ro.rb +1 -1
  54. data/lib/holidays/scandinavia.rb +18 -11
  55. data/lib/holidays/se.rb +1 -1
  56. data/lib/holidays/sg.rb +1 -1
  57. data/lib/holidays/si.rb +1 -1
  58. data/lib/holidays/sk.rb +1 -1
  59. data/lib/holidays/united_nations.rb +3 -3
  60. data/lib/holidays/ups.rb +1 -1
  61. data/lib/holidays/us.rb +1 -1
  62. data/lib/holidays/ve.rb +1 -1
  63. data/lib/holidays/version.rb +1 -1
  64. data/lib/holidays/vi.rb +1 -1
  65. data/lib/holidays/za.rb +1 -1
  66. data/test/data/test_custom_govt_holiday_defs.yaml +5 -0
  67. data/test/data/test_multiple_custom_holiday_defs.yaml +9 -0
  68. data/test/data/test_single_custom_holiday_defs.yaml +9 -0
  69. data/test/defs/test_defs_au.rb +32 -0
  70. data/test/defs/test_defs_ca.rb +25 -0
  71. data/test/defs/test_defs_cr.rb +22 -0
  72. data/test/defs/test_defs_de.rb +6 -6
  73. data/test/defs/test_defs_europe.rb +24 -0
  74. data/test/defs/test_defs_fed_ex.rb +21 -0
  75. data/test/defs/test_defs_federal_reserve.rb +2 -15
  76. data/test/defs/test_defs_jp.rb +1 -0
  77. data/test/defs/test_defs_north_america.rb +25 -0
  78. data/test/defs/test_defs_united_nations.rb +12 -0
  79. data/test/test_custom_holidays.rb +35 -0
  80. data/test/test_parse_definitions.rb +24 -0
  81. metadata +22 -3
  82. data/data/build_defs.rb +0 -157
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
+
3
+ class ParseDefinitionsTests < Test::Unit::TestCase
4
+
5
+ def test_single_parse_definition_file
6
+ module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region, 'test/data/test_single_custom_holiday_defs.yaml')
7
+
8
+ assert_equal false, module_src.empty?
9
+ assert_equal false, test_src.empty?
10
+ end
11
+
12
+ def test_parsing_without_def_file_results_in_error
13
+ assert_raises ArgumentError do
14
+ Holidays.parse_definition_files_and_return_source(:custom)
15
+ end
16
+ end
17
+
18
+ def test_parsing_of_multiple_definition_files
19
+ module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region_multiple, 'test/data/test_single_custom_holiday_defs.yaml', 'test/data/test_custom_govt_holiday_defs.yaml')
20
+
21
+ assert_equal false, module_src.empty?
22
+ assert_equal false, test_src.empty?
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,10 +58,10 @@ files:
58
58
  - data/au.yaml
59
59
  - data/be.yaml
60
60
  - data/br.yaml
61
- - data/build_defs.rb
62
61
  - data/ca.yaml
63
62
  - data/ch.yaml
64
63
  - data/cl.yaml
64
+ - data/cr.yaml
65
65
  - data/cz.yaml
66
66
  - data/de.yaml
67
67
  - data/dk.yaml
@@ -69,6 +69,7 @@ files:
69
69
  - data/el.yaml
70
70
  - data/es.yaml
71
71
  - data/federal_reserve.yaml
72
+ - data/fedex.yaml
72
73
  - data/fi.yaml
73
74
  - data/fr.yaml
74
75
  - data/gb.yaml
@@ -113,6 +114,7 @@ files:
113
114
  - lib/holidays/ca.rb
114
115
  - lib/holidays/ch.rb
115
116
  - lib/holidays/cl.rb
117
+ - lib/holidays/cr.rb
116
118
  - lib/holidays/cz.rb
117
119
  - lib/holidays/de.rb
118
120
  - lib/holidays/dk.rb
@@ -120,6 +122,7 @@ files:
120
122
  - lib/holidays/el.rb
121
123
  - lib/holidays/es.rb
122
124
  - lib/holidays/europe.rb
125
+ - lib/holidays/fed_ex.rb
123
126
  - lib/holidays/federal_reserve.rb
124
127
  - lib/holidays/fi.rb
125
128
  - lib/holidays/fr.rb
@@ -155,6 +158,9 @@ files:
155
158
  - lib/holidays/version.rb
156
159
  - lib/holidays/vi.rb
157
160
  - lib/holidays/za.rb
161
+ - test/data/test_custom_govt_holiday_defs.yaml
162
+ - test/data/test_multiple_custom_holiday_defs.yaml
163
+ - test/data/test_single_custom_holiday_defs.yaml
158
164
  - test/defs/test_defs_ar.rb
159
165
  - test/defs/test_defs_at.rb
160
166
  - test/defs/test_defs_au.rb
@@ -163,6 +169,7 @@ files:
163
169
  - test/defs/test_defs_ca.rb
164
170
  - test/defs/test_defs_ch.rb
165
171
  - test/defs/test_defs_cl.rb
172
+ - test/defs/test_defs_cr.rb
166
173
  - test/defs/test_defs_cz.rb
167
174
  - test/defs/test_defs_de.rb
168
175
  - test/defs/test_defs_dk.rb
@@ -170,6 +177,7 @@ files:
170
177
  - test/defs/test_defs_el.rb
171
178
  - test/defs/test_defs_es.rb
172
179
  - test/defs/test_defs_europe.rb
180
+ - test/defs/test_defs_fed_ex.rb
173
181
  - test/defs/test_defs_federal_reserve.rb
174
182
  - test/defs/test_defs_fi.rb
175
183
  - test/defs/test_defs_fr.rb
@@ -198,16 +206,19 @@ files:
198
206
  - test/defs/test_defs_sg.rb
199
207
  - test/defs/test_defs_si.rb
200
208
  - test/defs/test_defs_sk.rb
209
+ - test/defs/test_defs_united_nations.rb
201
210
  - test/defs/test_defs_ups.rb
202
211
  - test/defs/test_defs_us.rb
203
212
  - test/defs/test_defs_ve.rb
204
213
  - test/defs/test_defs_vi.rb
205
214
  - test/defs/test_defs_za.rb
206
215
  - test/test_all_regions.rb
216
+ - test/test_custom_holidays.rb
207
217
  - test/test_date.rb
208
218
  - test/test_helper.rb
209
219
  - test/test_holidays.rb
210
220
  - test/test_multiple_regions.rb
221
+ - test/test_parse_definitions.rb
211
222
  homepage: https://github.com/alexdunae/holidays
212
223
  licenses:
213
224
  - MIT
@@ -233,6 +244,9 @@ signing_key:
233
244
  specification_version: 4
234
245
  summary: A collection of Ruby methods to deal with statutory and other holidays.
235
246
  test_files:
247
+ - test/data/test_custom_govt_holiday_defs.yaml
248
+ - test/data/test_multiple_custom_holiday_defs.yaml
249
+ - test/data/test_single_custom_holiday_defs.yaml
236
250
  - test/defs/test_defs_ar.rb
237
251
  - test/defs/test_defs_at.rb
238
252
  - test/defs/test_defs_au.rb
@@ -241,6 +255,7 @@ test_files:
241
255
  - test/defs/test_defs_ca.rb
242
256
  - test/defs/test_defs_ch.rb
243
257
  - test/defs/test_defs_cl.rb
258
+ - test/defs/test_defs_cr.rb
244
259
  - test/defs/test_defs_cz.rb
245
260
  - test/defs/test_defs_de.rb
246
261
  - test/defs/test_defs_dk.rb
@@ -248,6 +263,7 @@ test_files:
248
263
  - test/defs/test_defs_el.rb
249
264
  - test/defs/test_defs_es.rb
250
265
  - test/defs/test_defs_europe.rb
266
+ - test/defs/test_defs_fed_ex.rb
251
267
  - test/defs/test_defs_federal_reserve.rb
252
268
  - test/defs/test_defs_fi.rb
253
269
  - test/defs/test_defs_fr.rb
@@ -276,13 +292,16 @@ test_files:
276
292
  - test/defs/test_defs_sg.rb
277
293
  - test/defs/test_defs_si.rb
278
294
  - test/defs/test_defs_sk.rb
295
+ - test/defs/test_defs_united_nations.rb
279
296
  - test/defs/test_defs_ups.rb
280
297
  - test/defs/test_defs_us.rb
281
298
  - test/defs/test_defs_ve.rb
282
299
  - test/defs/test_defs_vi.rb
283
300
  - test/defs/test_defs_za.rb
284
301
  - test/test_all_regions.rb
302
+ - test/test_custom_holidays.rb
285
303
  - test/test_date.rb
286
304
  - test/test_helper.rb
287
305
  - test/test_holidays.rb
288
306
  - test/test_multiple_regions.rb
307
+ - test/test_parse_definitions.rb
data/data/build_defs.rb DELETED
@@ -1,157 +0,0 @@
1
- require 'yaml'
2
-
3
- # Functions are stored in generated files as both Procs (:function) and
4
- # Strings (:function_id). The String version makes comparisons of Procs much
5
- # easier.
6
- #
7
- # TODO:
8
- # - better comparison of existing rules
9
- def parse_holiday_defs(module_name, files)
10
- regions = []
11
- rules_by_month = {}
12
- custom_methods = {}
13
- test_strs = []
14
-
15
- files.each do |file|
16
- def_file = YAML.load_file(file)
17
- puts " Loading #{file}"
18
- if def_file['months']
19
- puts " - importing dates..."
20
- def_file['months'].each do |month, definitions|
21
- rules_by_month[month] = [] unless rules_by_month[month]
22
- definitions.each do |definition|
23
- rule = {}
24
- definition.each do |key, val|
25
- rule[key] = val
26
- end
27
-
28
- rule['regions'] = rule['regions'].collect { |r| r.to_sym }
29
-
30
- regions << rule['regions']
31
-
32
- exists = false
33
- rules_by_month[month].each do |ex|
34
- if ex['name'] == rule['name'] and ex['wday'] == rule['wday'] and ex['mday'] == rule['mday'] and ex['week'] == rule['week'] and ex['type'] == rule['type'] and ex['function'] == rule['function'] and ex['observed'] == rule['observed']
35
- ex['regions'] << rule['regions'].flatten
36
- exists = true
37
- end
38
- end
39
- unless exists
40
- rules_by_month[month] << rule
41
- end
42
-
43
- end # /defs.each
44
- end
45
- end
46
-
47
- if def_file['methods']
48
- puts " - importing methods..."
49
- def_file['methods'].each do |name, code|
50
- custom_methods[name] = code
51
- end # /methods.each
52
- end
53
-
54
- if def_file['tests']
55
- puts " - importing tests..."
56
- test_strs << def_file['tests']
57
- end
58
- end
59
-
60
- # Build the definitions
61
- month_strs = []
62
- rules_by_month.each do |month, rules|
63
- month_str = " #{month.to_s} => ["
64
- rule_strings = []
65
- rules.each do |rule|
66
- str = '{'
67
- if rule['mday']
68
- str << ":mday => #{rule['mday']}, "
69
- elsif rule['function']
70
- str << ":function => lambda { |year| Holidays.#{rule['function']} }, "
71
- str << ":function_id => \"#{rule['function'].to_s}\", "
72
- else
73
- str << ":wday => #{rule['wday']}, :week => #{rule['week']}, "
74
- end
75
-
76
- if rule['observed']
77
- str << ":observed => lambda { |date| Holidays.#{rule['observed']}(date) }, "
78
- str << ":observed_id => \"#{rule['observed'].to_s}\", "
79
- end
80
-
81
- if rule['type']
82
- str << ":type => :#{rule['type']}, "
83
- end
84
-
85
- # shouldn't allow the same region twice
86
- str << ":name => \"#{rule['name']}\", :regions => [:" + rule['regions'].uniq.join(', :') + "]}"
87
- rule_strings << str
88
- end
89
- month_str << rule_strings.join(",\n ") + "]"
90
- month_strs << month_str
91
- end
92
-
93
- month_strs.join(",\n")
94
-
95
-
96
- # Build the methods
97
- method_str = ''
98
- custom_methods.each do |key, code|
99
- method_str << code + "\n\n"
100
- end
101
-
102
-
103
- # Build the module file
104
- module_src =<<-EOM
105
- # encoding: utf-8
106
- module Holidays
107
- # This file is generated by the Ruby Holidays gem.
108
- #
109
- # Definitions loaded: #{files.join(', ')}
110
- #
111
- # To use the definitions in this file, load it right after you load the
112
- # Holiday gem:
113
- #
114
- # require 'holidays'
115
- # require 'holidays/#{module_name.downcase}'
116
- #
117
- # All the definitions are available at https://github.com/alexdunae/holidays
118
- module #{module_name} # :nodoc:
119
- def self.defined_regions
120
- [:#{regions.flatten.uniq.join(', :')}]
121
- end
122
-
123
- def self.holidays_by_month
124
- {
125
- #{month_strs.join(",\n")}
126
- }
127
- end
128
- end
129
-
130
- #{method_str}
131
- end
132
-
133
- Holidays.merge_defs(Holidays::#{module_name}.defined_regions, Holidays::#{module_name}.holidays_by_month)
134
- EOM
135
-
136
-
137
- # Build the test file
138
- unless test_strs.empty?
139
- test_src =<<-EndOfTests
140
- # encoding: utf-8
141
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
142
-
143
- # This file is generated by the Ruby Holiday gem.
144
- #
145
- # Definitions loaded: #{files.join(', ')}
146
- class #{module_name.capitalize}DefinitionTests < Test::Unit::TestCase # :nodoc:
147
-
148
- def test_#{module_name.downcase}
149
- #{test_strs.join("\n\n")}
150
- end
151
- end
152
- EndOfTests
153
- end
154
-
155
- return module_src, test_src || ''
156
-
157
- end