Method: Aef::Weekling::Week.parse

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

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

Note:

Looks for patterns like this: 2011-W03

Parses the first week out of a string.

Parameters:

  • string (String)

    a string containing a week representation

Returns:

Raises:

  • (ArgumentError)

    if pattern cannot be found



52
53
54
55
56
57
58
59
# File 'lib/aef/weekling/week.rb', line 52

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