lib/what_day/client.rb in what_day-0.1.0 vs lib/what_day/client.rb in what_day-0.1.2

- old
+ new

@@ -1,19 +1,20 @@ module WhatDay class Client + MONTHS = '(jan||feb||mar||apr||may||jun||jul||aug||sep||oct||nov||dec||january||february||march||april||may||june||july||august||september||october||november||december||sept)'.freeze + def day(date) begin - day_int = date.yesterday.wday - Date::DAYS_INTO_WEEK.key(day_int).to_s.capitalize + Date::DAYNAMES[date.wday] rescue ArgumentError nil end end def method_missing(name, *args, &block) - if name.to_s =~ /^(beginning||end)_of_[a-z]+_\d+$/i + if name.to_s =~ Regexp.new("^(beginning||end)_of_#{MONTHS}_\\d+$", true) date = parse_date_string(name.to_s) day date else super end @@ -24,10 +25,10 @@ def parse_date_string(name) methods = name.split("_") selector = methods[0].downcase month = format_date_string methods[2] year = methods[3].to_i - str = "#{year} #{month}, 1" + str = "#{year}-#{month}-1" date = Date.parse str selector == "end" ? date.to_date.end_of_month : date end def format_date_string(str)