Class: IML::Patterns

Inherits:
Object
  • Object
show all
Defined in:
lib/iml/patterns.rb

Overview

Contains methods to build the regexp to match against the input filenames

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object

Mini format arrtibute DSL


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/iml/patterns.rb', line 16

def method_missing(method_name)
  m = config[method_name]
  super unless m
  if m.is_a?(Hash)
    "(?<#{method_name}>(#{m.keys.join('|')}))"
  elsif m.is_a?(Array)
    "(?<#{method_name}>(#{m.join('|')}))"
  elsif m.is_a?(String)
    "(?<#{method_name}>#{m})"
  end
end

Class Method Details

.configIML::Hash

Returns pattern config singleton version.

Returns:

  • (IML::Hash)

    pattern config singleton version


11
12
13
# File 'lib/iml/patterns.rb', line 11

def self.config
  new.config
end

Instance Method Details

#configIML::Hash

Returns pattern config.

Returns:


6
7
8
# File 'lib/iml/patterns.rb', line 6

def config
  IML::Hash.new YAML.load_file('patterns.yml')
end

#movieArray<Regex>

Returns Array of Regexp patterns to match filenames of Movies.

Returns:

  • (Array<Regex>)

    Array of Regexp patterns to match filenames of Movies


34
35
36
37
38
39
# File 'lib/iml/patterns.rb', line 34

def movie
  [
    /#{format_pattern('^%<title>s\.%<year>s\.?%<quality>s?\.%<source>s\.%<codec>s\.?%<audio>s?-?%<group>s\.%<extension>s$')}/i,
    /#{format_pattern('^%<title>s_\(%<year>s\)_\[%<quality>s,%<source>s,%<audio>s,%<codec>s\]_-_%<group>s.%<extension>s$')}/i
  ]
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns true when method name is a config key.

Returns:

  • (Boolean)

    true when method name is a config key


29
30
31
# File 'lib/iml/patterns.rb', line 29

def respond_to_missing?(method_name, _include_private = false)
  config.key?(method_name) || false
end

#tvArray<Regex>

Returns Array of Regexp patterns to match filenames of TV Shows.

Returns:

  • (Array<Regex>)

    Array of Regexp patterns to match filenames of TV Shows


42
43
44
45
46
# File 'lib/iml/patterns.rb', line 42

def tv
  [
    /#{format_pattern('^%<title>s.S%<season>sE%<episode>s.?%<episode_title>s?.?%<quality>s?.%<source>s.%<audio>s?\.?%<codec>s-%<group>s.%<extension>s$')}/i
  ]
end