Class: HolidayTools::Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/holiday_tools/locator.rb

Constant Summary collapse

@@reg_names =

names of the regions/subregions used in the holidays gem

{
at:     'Austria',
au:     'Australia',
au_act:  'Australia/Australian Capital Terretory',
au_nsw:  'Australia/New South Wales',
au_nt:  'Australia/Nothern Terretory',
au_qld: 'Australia/Queensland',
au_qld_brisbane: 'Australia/Queensland and Brisbane',
au_sa:  'Australia/South Australia',
au_tas: 'Australia/Tasmania',
au_vic: 'Australia/Victoria',
au_wa:  'Australia/Western Australia',
br:     'Brasilia',
ca:     'Canada',
ca_ab:  'Canada/Alberta',
ca_bc:  'Canada/British Columbia',
ca_mb:  'Canada/Manitoba',
    # ca_nb:  'Canada/New Brunswick',
ca_nf:  'Canada/Newfoundland',
ca_ns:  'Canada/Nova Scotia',
ca_nt:  'Canada/Northwest Territories',
ca_nu:  'Canada/Nunavut',
ca_on:  'Canada/Ontario',
    # ca_pe:  'Canada/Prince Edward Island',
ca_qc:  'Canada/Quebeck',
ca_sk:  'Canada/Saskatchewan',
ca_yk:  'Canada/Yukon',
cz:     'Czech Republic',
de:     'Germany',
de_bb:  'Germany/Brandenburg',
    # de_be:  'Germany/Berlin',
de_bw:  'Germany/Baden-Württemberg',
de_by:  'Germany/Bayern',
    # de_hb:  'Germany/Freie Hansestadt Bremen',
de_he:  'Germany/Hessen',
    # de_hh:  'Germany/Hamburg',
de_mv:  'Germany/Mecklenburg-Vorpommern',
    # de_ni:  'Germany/Niedersachsen',
de_nw:  'Germany/Nordrhein-Westfalen',
de_rp:  'Germany/Rheinland-Pfalz',
    # de_sh:  'Germany/Schleswig-Holstein',
de_sl:  'Germany/Saarland',
de_sn:  'Germany/Sachsen',
de_st:  'Germany/Sachsen-Anhalt',
de_th:  'Germany/Thüringen',
dk:     'Denmark',
el:     'Greece',
es:     'Spain',
es_an:  'Spain/Andalusia',
es_ar:  'Spain/Aragon',
es_ce:  'Spain/Ceuta',
es_cl:  'Spain/Castile and Leon',
es_cm:  'Spain/Castile-La Mancha',
es_cn:  'Spain/Canary Island',
es_ct:  'Spain/Catalonia',
es_ex:  'Spain/Extremadura',
es_ga:  'Spain/Galicia',
es_ib:  'Spain/Islas Baleares',
es_lo:  'Spain/La Rioja',
es_m:   'Spain/Madrid',
es_mu:  'Spain/Murcia',
es_na:  'Spain/Navarre',
es_o:   'Spain/Asturias',
es_pv:  'Spain/Euskadi (Pais Vasco - Basque Country)',
es_v:   'Spain/Valencia',
es_vc:  'Spain/Valencia',
fi:     'Finland',
fr:     'France',
gb:     'Great Britain',
gb_con: 'Great Britain/Cornwall',
gb_eaw: 'Great Britain/England and Wales',
gb_eng: 'Great Britain/England',
gb_gsy: 'Great Britain/Guernsey',
gb_iom: 'Great Britain/Isle of Man',
gb_jsy: 'Great Britain/Jersey',
gb_nir: 'Great Britain/Norther Ireland',
gb_sct: 'Great Britain/Scotland',
gb_wls: 'Great Britain/Wales',
gg:     'Guernsey',
ie:     'ireland',
im:     'Isle of Man',
it:     'Italy',
is:     'Iceland',
je:     'Jersey',
jp:     'Japan',
li:     'Liechtenstein',
mx:     'Mexico',
mx_pue: 'Mexico/Puebla',
nz:     'New Zealand',
nz_ak:  'New Zealand/Auckland',
nz_ca:  'New Zealand/Canterbury',
nz_ch:  'New Zealand/Chatham',
nz_hb:  "New Zealand/Hawke's Bay",
nz_mb:  'New Zealand/Marlboro',
nz_nl:  'New Zealand/Northland',
nz_ot:  'New Zealand/Otago',
nz_sc:  'New Zealand/South Canterbury',
nz_sl:  'New Zealand/Southland',
nz_we:  'New Zealand/Wellington',
nz_wl:  'New Zealand/Westland',
nl:     'Netherlands',
no:     'Norway',
pl:     'Poland',
pt:     'Portugal',
se:     'Sweden',
us:     'United States of America',
us_dc:  'United States of America/Washington DC',
za:     'South Africa'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter = []) ⇒ Locator

instance methods



174
175
176
# File 'lib/holiday_tools/locator.rb', line 174

def initialize( filter=[] )
  @filter = filter
end

Class Method Details

.show_regionsObject

loop over region names



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/holiday_tools/locator.rb', line 156

def self.show_regions
  regs = Holidays.regions.sort
  txt = []
  txt << "Region \tName"
  regs.each do |key|
    name = @@reg_names[key]
    if name
      txt << "%s \t%s" % [key, name]
    else
      txt << "%s: unexpected region id" % [key]
    end
  end
  txt
end

Instance Method Details

#show_holiday(date) ⇒ Object

get the name of a holiday and the regions, where it is observed



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/holiday_tools/locator.rb', line 179

def show_holiday(date)
  ans = Holidays.on(date, :any, :observed)
  # dat = date.to_s
  if ans.size > 0
    if @filter.size == 0
      show_all(date, ans)
    else
      show_filtered(date, ans)      
    end
  end
end

#show_month(date) ⇒ Object

loop over a month



199
200
201
202
203
# File 'lib/holiday_tools/locator.rb', line 199

def show_month(date)
  fm = date - date.mday + 1  # from 1. in month
  tm = (fm >> 1) - 1      # to last in month ( '>> 1' advances one month )
  show_holidays(fm, tm)
end

#show_week(date) ⇒ Object

loop over a week



192
193
194
195
196
# File 'lib/holiday_tools/locator.rb', line 192

def show_week(date)
  fw = date - date.wday   # from sunday
  tw = fw + 6             # to saturday
  show_holidays(fw, tw)
end

#show_year(date) ⇒ Object

loop over a year



207
208
209
210
211
# File 'lib/holiday_tools/locator.rb', line 207

def show_year(date)
  fy = date - date.yday + 1
  ty = Date.civil(fy.year, 12, 31)
  show_holidays(fy, ty)
end