Method: Aef::Weekling::WeekDay.parse

Defined in:
lib/aef/weekling/week_day.rb

.parse(string) ⇒ Aef::Weekling::WeekDay

Note:

Looks for patterns like this: 2011-W03-5

Parses the first week day out of a string.

Parameters:

  • string (String)

    a string containing a week-day representation

Returns:

Raises:

  • (ArgumentError)

    if pattern cannot be found



64
65
66
67
68
69
70
71
# File 'lib/aef/weekling/week_day.rb', line 64

def parse(string)
  if sub_matches = PARSE_PATTERN.match(string.to_s)
    original, year, week_index, day_index = *sub_matches
    new(year.to_i, week_index.to_i, day_index.to_i)
  else
    raise ArgumentError, 'No week day found for parsing'
  end
end