Move calendar mapping to config directory

This commit is contained in:
Julian Kornberger 2016-11-30 19:06:15 +01:00
parent dfbe15cb0e
commit c548502d84
2 changed files with 88 additions and 83 deletions

View file

@ -75,92 +75,19 @@ returnes preset of ical feeds
returns returns
{ {
'US' => 'http://www.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics', 'http://www.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics' => 'US',
... ...
} }
=end =end
def self.ical_feeds def self.ical_feeds
gfeeds = { data = YAML.load_file(Rails.root.join('config/holiday_calendars.yml'))
'Australia' => 'en.australian', url = data['url']
'Austria' => 'de.austrian',
'Argentina' => 'en.ar', data['countries'].map do |country, domain|
'Bahamas' => 'en.bs', [(url % { domain: domain }), country]
'Belarus' => 'en.by', end.to_h
'Brazil' => 'en.brazilian',
'Bulgaria' => 'en.bulgarian',
'Canada' => 'en.canadian',
'China' => 'en.china',
'Chile' => 'en.cl',
'Costa Rica' => 'en.cr',
'Colombia' => 'en.co',
'Croatia' => 'en.croatian',
'Cuba' => 'en.cu',
'Cyprus' => 'de.cy',
'Switzerland' => 'de.ch',
'Denmark' => 'da.danish',
'Netherlands' => 'nl.dutch',
'Egypt' => 'en.eg',
'Ethiopia' => 'en.et',
'Ecuador' => 'en.ec',
'Estonia' => 'en.ee',
'Finland' => 'en.finnish',
'France' => 'en.french',
'Germany' => 'de.german',
'Greece' => 'en.greek',
'Ghana' => 'en.gh',
'Hong Kong' => 'en.hong_kong',
'Haiti' => 'en.ht',
'Hungary' => 'en.hungarian',
'India' => 'en.indian',
'Indonesia' => 'en.indonesian',
'Iran' => 'en.ir',
'Ireland' => 'en.irish',
'Italy' => 'it.italian',
'Israel' => 'en.jewish',
'Japan' => 'en.japanese',
'Kuwait' => 'en.kw',
'Latvia' => 'en.latvian',
'Liechtenstein' => 'en.li',
'Lithuania' => 'en.lithuanian',
'Luxembourg' => 'en.lu',
'Malaysia' => 'en.malaysia',
'Mexico' => 'en.mexican',
'Morocco' => 'en.ma',
'Mauritius' => 'en.mu',
'Moldova' => 'en.md',
'New Zealand' => 'en.new_zealand',
'Norway' => 'en.norwegian',
'Philippines' => 'en.philippines',
'Poland' => 'en.polish',
'Portugal' => 'en.portuguese',
'Pakistan' => 'en.pk',
'Russia' => 'en.russian',
'Senegal' => 'en.sn',
'Singapore' => 'en.singapore',
'South Africa' => 'en.sa',
'South Korean' => 'en.south_korea',
'Spain' => 'en.spain',
'Slovakia' => 'en.slovak',
'Serbia' => 'en.rs',
'Slovenia' => 'en.slovenian',
'Sweden' => 'en.swedish',
'Taiwan' => 'en.taiwan',
'Thai' => 'en.th',
'Turkey' => 'en.turkish',
'UK' => 'en.uk',
'US' => 'en.usa',
'Ukraine' => 'en.ukrainian',
'Uruguay' => 'en.uy',
'Vietnam' => 'en.vietnamese',
'Venezuela' => 'en.ve',
}
all_feeds = {}
gfeeds.each { |key, name|
all_feeds["http://www.google.com/calendar/ical/#{name}%23holiday%40group.v.calendar.google.com/public/basic.ics"] = key
}
all_feeds
end end
=begin =begin
@ -201,7 +128,7 @@ returns
=end =end
def self.sync def self.sync
Calendar.all.each(&:sync) Calendar.find_each(&:sync)
true true
end end
@ -313,7 +240,7 @@ returns
# if changed calendar is default, set all others default to false # if changed calendar is default, set all others default to false
def sync_default def sync_default
return if !default return if !default
Calendar.all.each { |calendar| Calendar.find_each { |calendar|
next if calendar.id == id next if calendar.id == id
next if !calendar.default next if !calendar.default
calendar.default = false calendar.default = false
@ -331,7 +258,7 @@ returns
# check if sla's are refer to an existing calendar # check if sla's are refer to an existing calendar
default_calendar = Calendar.find_by(default: true) default_calendar = Calendar.find_by(default: true)
Sla.all.each { |sla| Sla.find_each { |sla|
if !sla.calendar_id if !sla.calendar_id
sla.calendar_id = default_calendar.id sla.calendar_id = default_calendar.id
sla.save! sla.save!

View file

@ -0,0 +1,78 @@
---
# % character in the URL has to be escaped (% => %%)
url: "http://www.google.com/calendar/ical/%{domain}%%23holiday%%40group.v.calendar.google.com/public/basic.ics"
# Mapping from country to domain
countries:
Australia: en.australian
Austria: de.austrian
Argentina: en.ar
Bahamas: en.bs
Belarus: en.by
Brazil: en.brazilian
Bulgaria: en.bulgarian
Canada: en.canadian
China: en.china
Chile: en.cl
Costa Rica: en.cr
Colombia: en.co
Croatia: en.croatian
Cuba: en.cu
Cyprus: de.cy
Switzerland: de.ch
Denmark: da.danish
Netherlands: nl.dutch
Egypt: en.eg
Ethiopia: en.et
Ecuador: en.ec
Estonia: en.ee
Finland: en.finnish
France: en.french
Germany: de.german
Greece: en.greek
Ghana: en.gh
Hong Kong: en.hong_kong
Haiti: en.ht
Hungary: en.hungarian
India: en.indian
Indonesia: en.indonesian
Iran: en.ir
Ireland: en.irish
Italy: it.italian
Israel: en.jewish
Japan: en.japanese
Kuwait: en.kw
Latvia: en.latvian
Liechtenstein: en.li
Lithuania: en.lithuanian
Luxembourg: en.lu
Malaysia: en.malaysia
Mexico: en.mexican
Morocco: en.ma
Mauritius: en.mu
Moldova: en.md
New Zealand: en.new_zealand
Norway: en.norwegian
Philippines: en.philippines
Poland: en.polish
Portugal: en.portuguese
Pakistan: en.pk
Russia: en.russian
Senegal: en.sn
Singapore: en.singapore
South Africa: en.sa
South Korean: en.south_korea
Spain: en.spain
Slovakia: en.slovak
Serbia: en.rs
Slovenia: en.slovenian
Sweden: en.swedish
Taiwan: en.taiwan
Thai: en.th
Turkey: en.turkish
UK: en.uk
US: en.usa
Ukraine: en.ukrainian
Uruguay: en.uy
Vietnam: en.vietnamese
Venezuela: en.ve