Class: VerifiedHolidays::CabinetOffice
- Inherits:
-
Object
- Object
- VerifiedHolidays::CabinetOffice
- Defined in:
- lib/verified_holidays/cabinet_office.rb
Defined Under Namespace
Classes: FetchError
Constant Summary collapse
- CSV_URL =
'https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv'
Class Method Summary collapse
Class Method Details
.fetch ⇒ Object
15 16 17 18 19 20 |
# File 'lib/verified_holidays/cabinet_office.rb', line 15 def self.fetch holidays = parse(download_csv) raise FetchError, "#{CSV_URL} returned no holidays" if holidays.empty? holidays end |
.parse(csv_string) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/verified_holidays/cabinet_office.rb', line 42 def self.parse(csv_string) holidays = {} CSV.parse(csv_string, headers: true) do |row| date_str = presence(row['国民の祝日・休日月日']) name = presence(row['国民の祝日・休日名称']) next if date_str.nil? || name.nil? holidays[Date.strptime(date_str, '%Y/%m/%d')] = name end holidays rescue Date::Error => e raise FetchError, "#{CSV_URL} contains an invalid date: #{e.}" end |