Class: Holidays

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

Constant Summary collapse

COUNTRY_CODES =
[:de, :at]
REGION_CODES_DE =
[:baden_wuerttemberg, :bayern, :berlin, :brandenburg, :bremen,
:hamburg, :hessen, :mecklenburg_vorpommern, :niedersachsen,
:nordrhein_westfalen, :rheinland_pfalz, :saarland, :sachsen,
:sachsen_anhalt, :schleswig_holstein, :thueringen]
HOLIDAY_CODES_DE =
[:winter, :ostern, :pfingsten, :sommer, :herbst, :weihnachten]
REGION_CODES_AT =
[:burgenland, :kaernten, :niederoesterreich, :oberoesterreich,
:salzburg,:steiermark, :tirol, :vorarlberg, :wien]
HOLIDAY_CODES_AT =
[:weihnachten, :semester, :ostern, :pfingsten, :sommer]
HOLIDAY_CODES_CH =
[:sport, :fruehling, :sommer, :herbst, :weihnachten]
REGION_HOLIDAY_TYPES =
{
  [:de,:baden_wuerttemberg] => [:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:bayern] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:berlin] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:brandenburg] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:bremen] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:hamburg] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:hessen] => [:ostern,:sommer,:herbst,:weihnachten],
  [:de,:mecklenburg_vorpommern] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:niedersachsen] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:nordrhein_westfalen] => [:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:rheinland_pfalz] => [:ostern,:sommer,:herbst,:weihnachten],
  [:de,:saarland] => [:winter,:ostern,:sommer,:herbst,:weihnachten],
  [:de,:sachsen] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:sachsen_anhalt] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:schleswig_holstein] => [:ostern,:pfingsten,:sommer,:herbst,:weihnachten],
  [:de,:thueringen] => [:winter,:ostern,:pfingsten,:sommer,:herbst,:weihnachten],

  [:at,:burgenland] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:kaernten] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:niederoesterreich] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:oberoesterreich] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:salzburg] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:steiermark] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:tirol] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:vorarlberg] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
  [:at,:wien] => [:semester,:ostern,:pfingsten,:sommer,:weihnachten],
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, country, region, holiday_type) ⇒ Holidays

Creates a new Holiday object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/holidays.rb', line 50

def initialize(year,country,region,holiday_type)
  @year = year
  @country = country
  @region = region
  @holiday_type = holiday_type
  @fortlaufend = true
  @extra_days = []
  found = false
  if HASH_FERIEN[[year,country,region,holiday_type]]
    @first,@last,@fortlaufend,@extra_days = HASH_FERIEN[[year,country,region,holiday_type]]
    found = true
  end
  unless found
    if false
    elsif t 2011,:de,:baden_wuerttemberg,:ostern
      #to do
      #	'Gruendonnerstag ist auch frei'
      #end
      @first = Date.new(2011,4,21)
      @last  = Date.new(2011,4,30)
      found = true
    elsif t 2011,:de,:baden_wuerttemberg,:sommer
      @first = Date.new(2011,7,28)
      @last  = Date.new(2011,9,10)
      found = true
    elsif t 2012,:de,:bayern,:ostern
      @first = Date.new(2012,4,2)
      @last = Date.new(2012,4,14)
      found = true
    elsif t 2011,:de,:bayern,:sommer
      @first = Date.new(2011,7,30)
      @last = Date.new(2011,9,12)
      found = true
    elsif t 2011,:de,:berlin,:sommer
      @first = Date.new(2011,6,29)
      @last = Date.new(2011,8,12)
      found = true
    elsif t 2011,:de,:brandenburg,:sommer
      @first = Date.new(2011,6,30)
      @last = Date.new(2011,8,13)
      found = true
    elsif t 2011,:de,:bremen,:sommer
      @first = Date.new(2011,7,7)
      @last = Date.new(2011,8,17)
      found = true
    elsif t 2011,:de,:hamburg,:sommer
      @first = Date.new(2011,6,30)
      @last = Date.new(2011,8,10)
      found = true
    elsif t 2011,:de,:hessen,:sommer
      @first = Date.new(2011,6,27)
      @last = Date.new(2011,8,5)
      found = true
    elsif t 2011,:de,:mecklenburg_vorpommern,:sommer
      @first = Date.new(2011,7,4)
      @last = Date.new(2011,8,13)
      found = true
    elsif t 2011,:de,:niedersachsen,:sommer
      @first = Date.new(2011,7,7)
      @last = Date.new(2011,8,17)
      found = true
    elsif t 2011,:de,:nordrhein_westfalen,:sommer
      @first = Date.new(2011,7,25)
      @last = Date.new(2011,9,6)
      found = true
    elsif t 2011,:de,:rheinland_pfalz,:sommer
      @first = Date.new(2011,6,27)
      @last = Date.new(2011,8,5)
      found = true
    elsif t 2011,:de,:saarland,:sommer
      @first = Date.new(2011,6,24)
      @last = Date.new(2011,8,6)
      found = true
    elsif t 2011,:de,:sachsen,:sommer
      @first = Date.new(2011,7,11)
      @last = Date.new(2011,8,19)
      found = true
    elsif t 2011,:de,:sachsen_anhalt,:sommer
      @first = Date.new(2011,7,11)
      @last = Date.new(2011,8,24)
      found = true
    elsif t 2011,:de,:schleswig_holstein,:sommer
      @first = Date.new(2011,7,4)
      @last = Date.new(2011,8,13)
      found = true
    elsif t 2011,:de,:thueringen,:sommer
      @first = Date.new(2011,7,11)
      @last = Date.new(2011,8,19)
      found = true
    elsif t 2011,:at,:burgenland,:sommer
      @first = Date.new(2011,7,2)
      @last = Date.new(2011,9,3)
      found = true
    elsif t 2011,:at,:kaernten,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:niederoesterreich,:sommer
      @first = Date.new(2011,7,2)
      @last = Date.new(2011,9,3)
      found = true
    elsif t 2011,:at,:oberoesterreich,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:salzburg,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:steiermark,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:tirol,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:vorarlberg,:sommer
      @first = Date.new(2011,7,9)
      @last = Date.new(2011,9,10)
      found = true
    elsif t 2011,:at,:wien,:sommer
      @first = Date.new(2011,7,2)
      @last = Date.new(2011,9,3)
      found = true
    end
  end
  unless found
    raise ArgumentError,
      "#{year} #{country} #{region} #{holiday_type} " +
      "nicht implementiert"
  end
end

Class Method Details

.countriesObject

Returns an array of all implemented countries ([:de, :at, ..])



195
196
197
# File 'lib/holidays.rb', line 195

def self.countries
  COUNTRY_CODES
end

.holiday_types(country, region = nil) ⇒ Object

Returns an array of all holiday types of a country and optionally a region ([:winter, :ostern, ..])



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/holidays.rb', line 215

def self.holiday_types(country,region=nil)
  case country
  when :de
    if region
      REGION_HOLIDAY_TYPES[[country,region]]
    else
      HOLIDAY_CODES_DE
    end
  when :at
    if region
      REGION_HOLIDAY_TYPES[[country,region]]
    else
      HOLIDAY_CODES_AT
    end
  when :ch
    #TODO: unterschiedliche in Schweiz?
    [:sport, :fruehling, :sommer, :herbst, :weihnachten]
  else
    raise ArgumentError, "Unknown country #{country}"
  end
end

.regions(country) ⇒ Object

Returns an array of all regions of a country ([:baden_wuerttemberg, ..])



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/holidays.rb', line 200

def self.regions(country)
  case country
  when :de
    REGION_CODES_DE
  when :at
    REGION_CODES_AT
  when :ch
    []
  else
    raise ArgumentError, "Unknown country #{country}"
  end
end

Instance Method Details

#resultObject Also known as: days

Erstellt ein Array mit allen Ferientagen @first und @last (einschliesslich der Samstage und Sonntage dazwischen) Falls es spaeter Ferien gibt, die irgendwie “Luecken” haben, muesste man das Array der Tage anders zusammenbauen.



188
189
190
# File 'lib/holidays.rb', line 188

def result
  build_result
end

#to_sObject



237
238
239
240
241
242
243
# File 'lib/holidays.rb', line 237

def to_s
  if days.size > 1
    "#{days.first} - #{days.last}"
  else
    "#{days.first}"
  end
end