holiday_tools 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/holiday_tools +9 -1
- data/lib/holiday_tools.rb +1 -278
- data/lib/holiday_tools/locator.rb +282 -0
- data/lib/holiday_tools/version.rb +1 -1
- metadata +3 -2
data/bin/holiday_tools
CHANGED
@@ -41,7 +41,11 @@ def get_opts
|
|
41
41
|
options.date = d
|
42
42
|
end
|
43
43
|
|
44
|
-
opts.on( '-v', '--
|
44
|
+
opts.on( '-v', '--version', "Flag for version output [Default: false]") do |v|
|
45
|
+
options.version = v
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on( '-t', '--test', "Flag for test output [Default: false]") do |v|
|
45
49
|
options.debug = v
|
46
50
|
end
|
47
51
|
|
@@ -92,6 +96,10 @@ if @opts.list
|
|
92
96
|
puts holidays.show_regions
|
93
97
|
exit
|
94
98
|
end
|
99
|
+
if @opts.version
|
100
|
+
puts HolidayTools::VERSION
|
101
|
+
exit
|
102
|
+
end
|
95
103
|
|
96
104
|
# distribute depending on mode
|
97
105
|
date = @opts.date
|
data/lib/holiday_tools.rb
CHANGED
@@ -1,284 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require "holiday_tools/version"
|
4
|
+
require "holiday_tools/locator"
|
4
5
|
|
5
6
|
module HolidayTools
|
6
|
-
class Locator
|
7
|
-
|
8
|
-
# prerequisit: gem install holidays
|
9
|
-
# see https://github.com/alexdunae/holidays
|
10
|
-
|
11
|
-
require "holidays"
|
12
|
-
require "holidays/at"
|
13
|
-
require "holidays/au"
|
14
|
-
require "holidays/br"
|
15
|
-
require "holidays/ca"
|
16
|
-
# require "holidays/ch"
|
17
|
-
require "holidays/cz"
|
18
|
-
require "holidays/de"
|
19
|
-
require "holidays/dk"
|
20
|
-
require "holidays/el"
|
21
|
-
require "holidays/es"
|
22
|
-
require "holidays/fi"
|
23
|
-
require "holidays/fr"
|
24
|
-
require "holidays/gb"
|
25
|
-
# require "holidays/hr"
|
26
|
-
# require "holidays/hu"
|
27
|
-
require "holidays/ie"
|
28
|
-
require "holidays/is"
|
29
|
-
require "holidays/it"
|
30
|
-
require "holidays/jp"
|
31
|
-
require "holidays/li"
|
32
|
-
require "holidays/mx"
|
33
|
-
require "holidays/nl"
|
34
|
-
require "holidays/no"
|
35
|
-
require "holidays/nz"
|
36
|
-
require "holidays/pl"
|
37
|
-
require "holidays/pt"
|
38
|
-
require "holidays/se"
|
39
|
-
require "holidays/us"
|
40
|
-
# require "holidays/vz"
|
41
|
-
require "holidays/za"
|
42
|
-
|
43
|
-
def initialize( filter )
|
44
|
-
@filter = filter
|
45
|
-
|
46
|
-
# names of the regions/subregions used in the holidays gem
|
47
|
-
@reg_names = {
|
48
|
-
at: 'Austria',
|
49
|
-
au: 'Australia',
|
50
|
-
au_act: 'Australia/Australian Capital Terretory',
|
51
|
-
au_nsw: 'Australia/New South Wales',
|
52
|
-
au_nt: 'Australia/Nothern Terretory',
|
53
|
-
au_qld: 'Australia/Queensland',
|
54
|
-
au_qld_brisbane: 'Australia/Queensland and Brisbane',
|
55
|
-
au_sa: 'Australia/South Australia',
|
56
|
-
au_tas: 'Australia/Tasmania',
|
57
|
-
au_vic: 'Australia/Victoria',
|
58
|
-
au_wa: 'Australia/Western Australia',
|
59
|
-
br: 'Brasilia',
|
60
|
-
ca: 'Canada',
|
61
|
-
ca_ab: 'Canada/Alberta',
|
62
|
-
ca_bc: 'Canada/British Columbia',
|
63
|
-
ca_mb: 'Canada/Manitoba',
|
64
|
-
ca_nb: 'Canada/New Brunswick',
|
65
|
-
ca_nf: 'Canada/Newfoundland',
|
66
|
-
ca_ns: 'Canada/Nova Scotia',
|
67
|
-
ca_nt: 'Canada/Northwest Territories',
|
68
|
-
ca_nu: 'Canada/Nunavut',
|
69
|
-
ca_on: 'Canada/Ontario',
|
70
|
-
ca_pe: 'Canada/Prince Edward Island',
|
71
|
-
ca_sk: 'Canada/Saskatchewan',
|
72
|
-
ca_qc: 'Canada/Quebeck',
|
73
|
-
ca_yk: 'Canada/Yukon',
|
74
|
-
cz: 'Czech Republic',
|
75
|
-
de: 'Germany',
|
76
|
-
de_bb: 'Germany/Brandenburg',
|
77
|
-
# de_be: 'Germany/Berlin',
|
78
|
-
de_bw: 'Germany/Baden-Württemberg',
|
79
|
-
de_by: 'Germany/Bayern',
|
80
|
-
# de_hb: 'Germany/Freie Hansestadt Bremen',
|
81
|
-
de_he: 'Germany/Hessen',
|
82
|
-
# de_hh: 'Germany/Hamburg',
|
83
|
-
de_mv: 'Germany/Mecklenburg-Vorpommern',
|
84
|
-
# de_ni: 'Germany/Niedersachsen',
|
85
|
-
de_nw: 'Germany/Nordrhein-Westfalen',
|
86
|
-
de_rp: 'Germany/Rheinland-Pfalz',
|
87
|
-
# de_sh: 'Germany/Schleswig-Holstein',
|
88
|
-
de_sl: 'Germany/Saarland',
|
89
|
-
de_sn: 'Germany/Sachsen',
|
90
|
-
de_st: 'Germany/Sachsen-Anhalt',
|
91
|
-
de_th: 'Germany/Thüringen',
|
92
|
-
dk: 'Denmark',
|
93
|
-
el: 'Greece',
|
94
|
-
es: 'Spain',
|
95
|
-
es_an: 'Spain/Andalusia',
|
96
|
-
es_ar: 'Spain/Aragon',
|
97
|
-
es_ce: 'Spain/Ceuta',
|
98
|
-
es_cl: 'Spain/Castile and Leon',
|
99
|
-
es_cm: 'Spain/Castile-La Mancha',
|
100
|
-
es_cn: 'Spain/Canary Island',
|
101
|
-
es_ct: 'Spain/Catalonia',
|
102
|
-
es_ex: 'Spain/Extremadura',
|
103
|
-
es_ga: 'Spain/Galicia',
|
104
|
-
es_ib: 'Spain/Islas Baleares',
|
105
|
-
es_lo: 'Spain/La Rioja',
|
106
|
-
es_m: 'Spain/Madrid',
|
107
|
-
es_mu: 'Spain/Murcia',
|
108
|
-
es_na: 'Spain/Navarre',
|
109
|
-
es_o: 'Spain/Asturias',
|
110
|
-
es_pv: 'Spain/Euskadi (Pais Vasco - Basque Country)',
|
111
|
-
es_v: 'Spain/Valencia',
|
112
|
-
es_vc: 'Spain/Valencia',
|
113
|
-
fi: 'Finland',
|
114
|
-
fr: 'France',
|
115
|
-
gb: 'Great Britain',
|
116
|
-
gb_eng: 'Great Britain/England',
|
117
|
-
gb_wls: 'Great Britain/Wales',
|
118
|
-
gb_eaw: 'Great Britain/England and Wales',
|
119
|
-
gb_nir: 'Great Britain/Norther Ireland',
|
120
|
-
gb_sct: 'Great Britain/Scotland',
|
121
|
-
gb_jsy: 'Great Britain/Jersey',
|
122
|
-
gb_gsy: 'Great Britain/Guernsey',
|
123
|
-
gb_con: 'Great Britain/Cornwall',
|
124
|
-
gb_iom: 'Great Britain/Isle of Man',
|
125
|
-
gg: 'Guernsey',
|
126
|
-
ie: 'ireland',
|
127
|
-
im: 'Isle of Man',
|
128
|
-
it: 'Italy',
|
129
|
-
is: 'Iceland',
|
130
|
-
je: 'Jersey',
|
131
|
-
jp: 'Japan',
|
132
|
-
li: 'Liechtenstein',
|
133
|
-
mx: 'Mexico',
|
134
|
-
mx_pue: 'Mexico/Puebla',
|
135
|
-
nz: 'New Zealand',
|
136
|
-
nz_ak: 'New Zealand/Auckland',
|
137
|
-
nz_ca: 'New Zealand/Canterbury',
|
138
|
-
nz_ch: 'New Zealand/Chatham',
|
139
|
-
nz_hb: "New Zealand/Hawke's Bay",
|
140
|
-
nz_mb: 'New Zealand/Marlboro',
|
141
|
-
nz_nl: 'New Zealand/Northland',
|
142
|
-
nz_ot: 'New Zealand/Otago',
|
143
|
-
nz_sc: 'New Zealand/South Canterbury',
|
144
|
-
nz_sl: 'New Zealand/Southland',
|
145
|
-
nz_we: 'New Zealand/Wellington',
|
146
|
-
nz_wl: 'New Zealand/Westland',
|
147
|
-
nl: 'Netherlands',
|
148
|
-
no: 'Norway',
|
149
|
-
pl: 'Poland',
|
150
|
-
pt: 'Portugal',
|
151
|
-
se: 'Sweden',
|
152
|
-
us: 'United States of America',
|
153
|
-
us_dc: 'United States of America/Washington DC',
|
154
|
-
za: 'South Africa'
|
155
|
-
}
|
156
|
-
end
|
157
|
-
|
158
|
-
# loop over region names
|
159
|
-
def show_regions
|
160
|
-
txt = []
|
161
|
-
txt << "Region \tName"
|
162
|
-
@reg_names.each do |key, val|
|
163
|
-
txt << "%s \t%s" % [key, val]
|
164
|
-
end
|
165
|
-
txt
|
166
|
-
end
|
167
|
-
|
168
|
-
# get the name of a holiday and the regions, where it is observed
|
169
|
-
def show_holiday(date)
|
170
|
-
ans = Holidays.on(date, :any, :observed)
|
171
|
-
# dat = date.to_s
|
172
|
-
if ans.size > 0
|
173
|
-
if @filter.size == 0
|
174
|
-
show_all(date, ans)
|
175
|
-
else
|
176
|
-
show_filtered(date, ans)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
# loop over a week
|
182
|
-
def show_week(date)
|
183
|
-
fw = date - date.wday # from sunday
|
184
|
-
tw = fw + 6 # to saturday
|
185
|
-
show_holidays(fw, tw)
|
186
|
-
end
|
187
|
-
|
188
|
-
# loop over a month
|
189
|
-
def show_month(date)
|
190
|
-
fm = date - date.mday + 1 # from 1. in month
|
191
|
-
tm = (fm >> 1) - 1 # to last in month ( '>> 1' advances one month )
|
192
|
-
show_holidays(fm, tm)
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
# loop over a year
|
197
|
-
def show_year(date)
|
198
|
-
fy = date - date.yday + 1
|
199
|
-
ty = Date.civil(fy.year, 12, 31)
|
200
|
-
show_holidays(fy, ty)
|
201
|
-
end
|
202
|
-
|
203
|
-
private
|
204
|
-
# get the name of a weekday
|
205
|
-
def wday_nam(wday)
|
206
|
-
name = %w( Sunday Monday Tuesday Wednesday Thursday Friday Saturday )
|
207
|
-
name[wday]
|
208
|
-
end
|
209
|
-
|
210
|
-
# show the date
|
211
|
-
def show_dat(dat)
|
212
|
-
"%s (%s)" % [dat.to_s, wday_nam(dat.wday)]
|
213
|
-
end
|
214
|
-
|
215
|
-
# show the name of the holiday
|
216
|
-
def show_nam(nam)
|
217
|
-
"\t %s" % [ nam ]
|
218
|
-
end
|
219
|
-
|
220
|
-
# show the expanded name of a region
|
221
|
-
def show_reg(reg)
|
222
|
-
rn = @reg_names[reg]
|
223
|
-
if rn
|
224
|
-
"\t \t %s" % [ rn ]
|
225
|
-
else
|
226
|
-
"\t \t :%s (?)" % [ reg ]
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
# show without region filter
|
231
|
-
def show_all(dat, ans)
|
232
|
-
txt = []
|
233
|
-
txt << show_dat(dat)
|
234
|
-
ans.each do |entry|
|
235
|
-
nam = entry[:name]
|
236
|
-
txt << show_nam(nam)
|
237
|
-
entry[:regions].each do |reg|
|
238
|
-
txt << show_reg(reg)
|
239
|
-
end
|
240
|
-
end
|
241
|
-
txt
|
242
|
-
end
|
243
|
-
|
244
|
-
# show with region filter
|
245
|
-
def show_filtered(dat, ans)
|
246
|
-
txt = []
|
247
|
-
date_shown = false
|
248
|
-
ans.each do |entry|
|
249
|
-
nam = entry[:name]
|
250
|
-
name_shown = false
|
251
|
-
entry[:regions].each do |reg|
|
252
|
-
@filter.each do |pat|
|
253
|
-
# construct a pattern
|
254
|
-
pattern = Regexp.new(pat)
|
255
|
-
if reg.to_s =~ pattern
|
256
|
-
# we have a match
|
257
|
-
unless date_shown
|
258
|
-
txt << show_dat(dat)
|
259
|
-
date_shown = true
|
260
|
-
end
|
261
|
-
unless name_shown
|
262
|
-
txt << show_nam(nam)
|
263
|
-
name_shown = true
|
264
|
-
end
|
265
|
-
txt << show_reg(reg)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
txt
|
271
|
-
end
|
272
|
-
|
273
|
-
# loop over a range of dates
|
274
|
-
def show_holidays(from_date, to_date)
|
275
|
-
txt = []
|
276
|
-
from_date.upto(to_date) do |date|
|
277
|
-
res = show_holiday(date)
|
278
|
-
txt << res if res
|
279
|
-
end
|
280
|
-
txt
|
281
|
-
end
|
282
|
-
|
283
|
-
end # class
|
284
7
|
end # module
|
@@ -0,0 +1,282 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module HolidayTools
|
4
|
+
class Locator
|
5
|
+
|
6
|
+
# prerequisit: gem install holidays
|
7
|
+
# see https://github.com/alexdunae/holidays
|
8
|
+
|
9
|
+
require "holidays"
|
10
|
+
require "holidays/at"
|
11
|
+
require "holidays/au"
|
12
|
+
require "holidays/br"
|
13
|
+
require "holidays/ca"
|
14
|
+
# require "holidays/ch"
|
15
|
+
require "holidays/cz"
|
16
|
+
require "holidays/de"
|
17
|
+
require "holidays/dk"
|
18
|
+
require "holidays/el"
|
19
|
+
require "holidays/es"
|
20
|
+
require "holidays/fi"
|
21
|
+
require "holidays/fr"
|
22
|
+
require "holidays/gb"
|
23
|
+
# require "holidays/hr"
|
24
|
+
# require "holidays/hu"
|
25
|
+
require "holidays/ie"
|
26
|
+
require "holidays/is"
|
27
|
+
require "holidays/it"
|
28
|
+
require "holidays/jp"
|
29
|
+
require "holidays/li"
|
30
|
+
require "holidays/mx"
|
31
|
+
require "holidays/nl"
|
32
|
+
require "holidays/no"
|
33
|
+
require "holidays/nz"
|
34
|
+
require "holidays/pl"
|
35
|
+
require "holidays/pt"
|
36
|
+
require "holidays/se"
|
37
|
+
require "holidays/us"
|
38
|
+
# require "holidays/vz"
|
39
|
+
require "holidays/za"
|
40
|
+
|
41
|
+
def initialize( filter )
|
42
|
+
@filter = filter
|
43
|
+
|
44
|
+
# names of the regions/subregions used in the holidays gem
|
45
|
+
@reg_names = {
|
46
|
+
at: 'Austria',
|
47
|
+
au: 'Australia',
|
48
|
+
au_act: 'Australia/Australian Capital Terretory',
|
49
|
+
au_nsw: 'Australia/New South Wales',
|
50
|
+
au_nt: 'Australia/Nothern Terretory',
|
51
|
+
au_qld: 'Australia/Queensland',
|
52
|
+
au_qld_brisbane: 'Australia/Queensland and Brisbane',
|
53
|
+
au_sa: 'Australia/South Australia',
|
54
|
+
au_tas: 'Australia/Tasmania',
|
55
|
+
au_vic: 'Australia/Victoria',
|
56
|
+
au_wa: 'Australia/Western Australia',
|
57
|
+
br: 'Brasilia',
|
58
|
+
ca: 'Canada',
|
59
|
+
ca_ab: 'Canada/Alberta',
|
60
|
+
ca_bc: 'Canada/British Columbia',
|
61
|
+
ca_mb: 'Canada/Manitoba',
|
62
|
+
ca_nb: 'Canada/New Brunswick',
|
63
|
+
ca_nf: 'Canada/Newfoundland',
|
64
|
+
ca_ns: 'Canada/Nova Scotia',
|
65
|
+
ca_nt: 'Canada/Northwest Territories',
|
66
|
+
ca_nu: 'Canada/Nunavut',
|
67
|
+
ca_on: 'Canada/Ontario',
|
68
|
+
ca_pe: 'Canada/Prince Edward Island',
|
69
|
+
ca_sk: 'Canada/Saskatchewan',
|
70
|
+
ca_qc: 'Canada/Quebeck',
|
71
|
+
ca_yk: 'Canada/Yukon',
|
72
|
+
cz: 'Czech Republic',
|
73
|
+
de: 'Germany',
|
74
|
+
de_bb: 'Germany/Brandenburg',
|
75
|
+
# de_be: 'Germany/Berlin',
|
76
|
+
de_bw: 'Germany/Baden-Württemberg',
|
77
|
+
de_by: 'Germany/Bayern',
|
78
|
+
# de_hb: 'Germany/Freie Hansestadt Bremen',
|
79
|
+
de_he: 'Germany/Hessen',
|
80
|
+
# de_hh: 'Germany/Hamburg',
|
81
|
+
de_mv: 'Germany/Mecklenburg-Vorpommern',
|
82
|
+
# de_ni: 'Germany/Niedersachsen',
|
83
|
+
de_nw: 'Germany/Nordrhein-Westfalen',
|
84
|
+
de_rp: 'Germany/Rheinland-Pfalz',
|
85
|
+
# de_sh: 'Germany/Schleswig-Holstein',
|
86
|
+
de_sl: 'Germany/Saarland',
|
87
|
+
de_sn: 'Germany/Sachsen',
|
88
|
+
de_st: 'Germany/Sachsen-Anhalt',
|
89
|
+
de_th: 'Germany/Thüringen',
|
90
|
+
dk: 'Denmark',
|
91
|
+
el: 'Greece',
|
92
|
+
es: 'Spain',
|
93
|
+
es_an: 'Spain/Andalusia',
|
94
|
+
es_ar: 'Spain/Aragon',
|
95
|
+
es_ce: 'Spain/Ceuta',
|
96
|
+
es_cl: 'Spain/Castile and Leon',
|
97
|
+
es_cm: 'Spain/Castile-La Mancha',
|
98
|
+
es_cn: 'Spain/Canary Island',
|
99
|
+
es_ct: 'Spain/Catalonia',
|
100
|
+
es_ex: 'Spain/Extremadura',
|
101
|
+
es_ga: 'Spain/Galicia',
|
102
|
+
es_ib: 'Spain/Islas Baleares',
|
103
|
+
es_lo: 'Spain/La Rioja',
|
104
|
+
es_m: 'Spain/Madrid',
|
105
|
+
es_mu: 'Spain/Murcia',
|
106
|
+
es_na: 'Spain/Navarre',
|
107
|
+
es_o: 'Spain/Asturias',
|
108
|
+
es_pv: 'Spain/Euskadi (Pais Vasco - Basque Country)',
|
109
|
+
es_v: 'Spain/Valencia',
|
110
|
+
es_vc: 'Spain/Valencia',
|
111
|
+
fi: 'Finland',
|
112
|
+
fr: 'France',
|
113
|
+
gb: 'Great Britain',
|
114
|
+
gb_eng: 'Great Britain/England',
|
115
|
+
gb_wls: 'Great Britain/Wales',
|
116
|
+
gb_eaw: 'Great Britain/England and Wales',
|
117
|
+
gb_nir: 'Great Britain/Norther Ireland',
|
118
|
+
gb_sct: 'Great Britain/Scotland',
|
119
|
+
gb_jsy: 'Great Britain/Jersey',
|
120
|
+
gb_gsy: 'Great Britain/Guernsey',
|
121
|
+
gb_con: 'Great Britain/Cornwall',
|
122
|
+
gb_iom: 'Great Britain/Isle of Man',
|
123
|
+
gg: 'Guernsey',
|
124
|
+
ie: 'ireland',
|
125
|
+
im: 'Isle of Man',
|
126
|
+
it: 'Italy',
|
127
|
+
is: 'Iceland',
|
128
|
+
je: 'Jersey',
|
129
|
+
jp: 'Japan',
|
130
|
+
li: 'Liechtenstein',
|
131
|
+
mx: 'Mexico',
|
132
|
+
mx_pue: 'Mexico/Puebla',
|
133
|
+
nz: 'New Zealand',
|
134
|
+
nz_ak: 'New Zealand/Auckland',
|
135
|
+
nz_ca: 'New Zealand/Canterbury',
|
136
|
+
nz_ch: 'New Zealand/Chatham',
|
137
|
+
nz_hb: "New Zealand/Hawke's Bay",
|
138
|
+
nz_mb: 'New Zealand/Marlboro',
|
139
|
+
nz_nl: 'New Zealand/Northland',
|
140
|
+
nz_ot: 'New Zealand/Otago',
|
141
|
+
nz_sc: 'New Zealand/South Canterbury',
|
142
|
+
nz_sl: 'New Zealand/Southland',
|
143
|
+
nz_we: 'New Zealand/Wellington',
|
144
|
+
nz_wl: 'New Zealand/Westland',
|
145
|
+
nl: 'Netherlands',
|
146
|
+
no: 'Norway',
|
147
|
+
pl: 'Poland',
|
148
|
+
pt: 'Portugal',
|
149
|
+
se: 'Sweden',
|
150
|
+
us: 'United States of America',
|
151
|
+
us_dc: 'United States of America/Washington DC',
|
152
|
+
za: 'South Africa'
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
# loop over region names
|
157
|
+
def show_regions
|
158
|
+
txt = []
|
159
|
+
txt << "Region \tName"
|
160
|
+
@reg_names.each do |key, val|
|
161
|
+
txt << "%s \t%s" % [key, val]
|
162
|
+
end
|
163
|
+
txt
|
164
|
+
end
|
165
|
+
|
166
|
+
# get the name of a holiday and the regions, where it is observed
|
167
|
+
def show_holiday(date)
|
168
|
+
ans = Holidays.on(date, :any, :observed)
|
169
|
+
# dat = date.to_s
|
170
|
+
if ans.size > 0
|
171
|
+
if @filter.size == 0
|
172
|
+
show_all(date, ans)
|
173
|
+
else
|
174
|
+
show_filtered(date, ans)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# loop over a week
|
180
|
+
def show_week(date)
|
181
|
+
fw = date - date.wday # from sunday
|
182
|
+
tw = fw + 6 # to saturday
|
183
|
+
show_holidays(fw, tw)
|
184
|
+
end
|
185
|
+
|
186
|
+
# loop over a month
|
187
|
+
def show_month(date)
|
188
|
+
fm = date - date.mday + 1 # from 1. in month
|
189
|
+
tm = (fm >> 1) - 1 # to last in month ( '>> 1' advances one month )
|
190
|
+
show_holidays(fm, tm)
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
# loop over a year
|
195
|
+
def show_year(date)
|
196
|
+
fy = date - date.yday + 1
|
197
|
+
ty = Date.civil(fy.year, 12, 31)
|
198
|
+
show_holidays(fy, ty)
|
199
|
+
end
|
200
|
+
|
201
|
+
private
|
202
|
+
# get the name of a weekday
|
203
|
+
def wday_nam(wday)
|
204
|
+
name = %w( Sunday Monday Tuesday Wednesday Thursday Friday Saturday )
|
205
|
+
name[wday]
|
206
|
+
end
|
207
|
+
|
208
|
+
# show the date
|
209
|
+
def show_dat(dat)
|
210
|
+
"%s (%s)" % [dat.to_s, wday_nam(dat.wday)]
|
211
|
+
end
|
212
|
+
|
213
|
+
# show the name of the holiday
|
214
|
+
def show_nam(nam)
|
215
|
+
"\t %s" % [ nam ]
|
216
|
+
end
|
217
|
+
|
218
|
+
# show the expanded name of a region
|
219
|
+
def show_reg(reg)
|
220
|
+
rn = @reg_names[reg]
|
221
|
+
if rn
|
222
|
+
"\t \t %s" % [ rn ]
|
223
|
+
else
|
224
|
+
"\t \t :%s (?)" % [ reg ]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# show without region filter
|
229
|
+
def show_all(dat, ans)
|
230
|
+
txt = []
|
231
|
+
txt << show_dat(dat)
|
232
|
+
ans.each do |entry|
|
233
|
+
nam = entry[:name]
|
234
|
+
txt << show_nam(nam)
|
235
|
+
entry[:regions].each do |reg|
|
236
|
+
txt << show_reg(reg)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
txt
|
240
|
+
end
|
241
|
+
|
242
|
+
# show with region filter
|
243
|
+
def show_filtered(dat, ans)
|
244
|
+
txt = []
|
245
|
+
date_shown = false
|
246
|
+
ans.each do |entry|
|
247
|
+
nam = entry[:name]
|
248
|
+
name_shown = false
|
249
|
+
entry[:regions].each do |reg|
|
250
|
+
@filter.each do |pat|
|
251
|
+
# construct a pattern
|
252
|
+
pattern = Regexp.new(pat)
|
253
|
+
if reg.to_s =~ pattern
|
254
|
+
# we have a match
|
255
|
+
unless date_shown
|
256
|
+
txt << show_dat(dat)
|
257
|
+
date_shown = true
|
258
|
+
end
|
259
|
+
unless name_shown
|
260
|
+
txt << show_nam(nam)
|
261
|
+
name_shown = true
|
262
|
+
end
|
263
|
+
txt << show_reg(reg)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
txt
|
269
|
+
end
|
270
|
+
|
271
|
+
# loop over a range of dates
|
272
|
+
def show_holidays(from_date, to_date)
|
273
|
+
txt = []
|
274
|
+
from_date.upto(to_date) do |date|
|
275
|
+
res = show_holiday(date)
|
276
|
+
txt << res if res
|
277
|
+
end
|
278
|
+
txt
|
279
|
+
end
|
280
|
+
|
281
|
+
end # class
|
282
|
+
end # module
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holiday_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-06-
|
12
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: holidays
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- bin/holiday_tools
|
61
61
|
- holiday_tools.gemspec
|
62
62
|
- lib/holiday_tools.rb
|
63
|
+
- lib/holiday_tools/locator.rb
|
63
64
|
- lib/holiday_tools/version.rb
|
64
65
|
homepage: ''
|
65
66
|
licenses: []
|