Class: Moviesort::TVShow::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/moviesort/tv_show.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Parser

Returns a new instance of Parser.



30
31
32
# File 'lib/moviesort/tv_show.rb', line 30

def initialize(filename)
  @filename = sanitize(filename)
end

Instance Method Details

#extract_data_from_pattern_match(match) ⇒ Object



44
45
46
# File 'lib/moviesort/tv_show.rb', line 44

def extract_data_from_pattern_match(match)
  [match[1], *match[2..3].map { |s| s.to_i }]
end

#parseObject



34
35
36
37
38
39
40
41
42
# File 'lib/moviesort/tv_show.rb', line 34

def parse
  patterns = [
    /(.*)\sS(\d+)E(\d+)/i, 
    /(.*)\s(\d{1,2})x(\d+)/,
    /(.*)\s(\d{1})(\d{2})/
  ]
  match = patterns.map { |regex| @filename.match(regex) }.compact.first
  extract_data_from_pattern_match(match)
end

#sanitize(filename) ⇒ Object



48
49
50
# File 'lib/moviesort/tv_show.rb', line 48

def sanitize(filename)
  filename.gsub(/\./, ' ').gsub(/-/, ' ').squeeze(' ')
end