class Torganiser::Matcher

A matcher that can extract semantic information from a properly named file.

Public Class Methods

match(basename) click to toggle source
# File lib/torganiser/matcher.rb, line 6
def match(basename)
  pattern.match basename
end

Private Class Methods

long_format() click to toggle source
# File lib/torganiser/matcher.rb, line 41
def long_format
  [
    's(?<season>\d+)',  # season number
    'e(?<episode>\d+)', # episode number
    '(e\d+)?'           # optional second episode number, ignored
  ].join('\s?')         # optionally space separated
end
one_of(*args) click to toggle source
# File lib/torganiser/matcher.rb, line 58
def one_of(*args)
  MatchOne.new(args)
end
pattern() click to toggle source
# File lib/torganiser/matcher.rb, line 12
def pattern
  @pattern ||= /^
    #{series}                  # Series name, and possibly year
    #{separator}#{season_info} # season info
    #{separator}.*$            # stuff we don't care about
  /ix
end
season_info() click to toggle source
# File lib/torganiser/matcher.rb, line 37
def season_info
  one_of long_format, short_format, special
end
separator() click to toggle source
# File lib/torganiser/matcher.rb, line 20
def separator
  @separator ||= one_of '\.', '\s', '\s?\-\s?'
end
series() click to toggle source
# File lib/torganiser/matcher.rb, line 24
def series
  # Series with year takes precedence
  one_of series_with_year, series_without_year
end
series_with_year() click to toggle source
# File lib/torganiser/matcher.rb, line 33
def series_with_year
  '(?<name>.*)\.(?<year>\d{4})'
end
series_without_year() click to toggle source
# File lib/torganiser/matcher.rb, line 29
def series_without_year
  '(?<name>.*)'
end
short_format() click to toggle source
# File lib/torganiser/matcher.rb, line 49
def short_format
  '\[?(?<season>\d+)x?(?<episode>\d{2})\]?'
end
special() click to toggle source
# File lib/torganiser/matcher.rb, line 53
def special
  # specials don't fit nicely into the season/episode model.
  "s(?<season>0)0|s(?<season>\\d+)#{separator}special"
end