Class: HolidayJp::Holiday

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

Constant Summary collapse

WDAY_NAMES =
%w(      )
EN_HOLIDAY_NAMES =
{
  "元日" => "New Year's Day",
  "成人の日" => "Coming of Age Day",
  "建国記念の日" => "National Foundation Day",
  "春分の日" => "Vernal Equinox Day",
  "憲法記念日" => "Constitution Memorial Day",
  "みどりの日" => "Greenery Day",
  "こどもの日" => "Children's Day",
  "海の日" => "Marine Day",
  "敬老の日" => "Respect for the Aged Day",
  "秋分の日" => "Autumnal Equinox Day",
  "体育の日" => "Health and Sports Day",
  "文化の日" => "National Culture Day",
  "勤労感謝の日" => "Labor Thanksgiving Day",
  "天皇誕生日" => "Emperor's Birthday",
  "昭和の日" => "Showa Day",
  "振替休日" => "Holiday in lieu",
  "国民の休日" => "Citizen's Holiday",
  "即位礼正殿の儀" => "The Ceremony of the Enthronement of His Majesty th Emperor (at the Seiden)",
  "昭和天皇の大喪の礼" => "The Funeral Ceremony of Emperor Showa.",
  "皇太子徳仁親王の結婚の儀" => "The Rite of Wedding of HIH Crown Prince Naruhito"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, name) ⇒ Holiday

Returns a new instance of Holiday.



31
32
33
34
# File 'lib/holiday_jp/holiday.rb', line 31

def initialize(date, name)
  @date = parse_date(date)
  @name = name
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



30
31
32
# File 'lib/holiday_jp/holiday.rb', line 30

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/holiday_jp/holiday.rb', line 30

def name
  @name
end

Instance Method Details

#name_enObject



36
37
38
# File 'lib/holiday_jp/holiday.rb', line 36

def name_en
  EN_HOLIDAY_NAMES[name]
end

#parse_date(date) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/holiday_jp/holiday.rb', line 45

def parse_date(date)
  begin
    Date.parse(date)
  rescue ArgumentError
    raise ArgumentError, "invalid date on :#{date}, #{name}"
  end
end

#wday_nameObject Also known as: week



40
41
42
# File 'lib/holiday_jp/holiday.rb', line 40

def wday_name
  WDAY_NAMES[date.wday]
end