Class: IML::Patterns
- Inherits:
-
Object
- Object
- IML::Patterns
- Defined in:
- lib/iml/patterns.rb
Overview
Contains methods to build the regexp to match against the input filenames
Class Method Summary collapse
-
.config ⇒ IML::Hash
Pattern config singleton version.
Instance Method Summary collapse
-
#config ⇒ IML::Hash
Pattern config.
-
#method_missing(method_name) ⇒ Object
Mini format arrtibute DSL.
-
#movie ⇒ Array<Regex>
Array of Regexp patterns to match filenames of Movies.
-
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
True when method name is a config key.
-
#tv ⇒ Array<Regex>
Array of Regexp patterns to match filenames of TV Shows.
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
.config ⇒ IML::Hash
Returns pattern config singleton version.
11 12 13 |
# File 'lib/iml/patterns.rb', line 11 def self.config new.config end |
Instance Method Details
#config ⇒ IML::Hash
Returns pattern config.
6 7 8 |
# File 'lib/iml/patterns.rb', line 6 def config IML::Hash.new ::YAML.load_file(pattern_file) end |
#movie ⇒ Array<Regex>
Returns 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.
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 |
#tv ⇒ Array<Regex>
Returns 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 |