Class: Showfix::Parser
- Inherits:
-
Object
- Object
- Showfix::Parser
- Defined in:
- lib/showfix/parser.rb
Constant Summary collapse
- PATTERNS =
matchData pre_match / post_match for getting data after the matched part
[ # Show.Season.01.Episode.01.Title /^(?<series>.*)(?:\.)?Season(?:\.)?(?<season>\d+)(?:\.)?Episode(?<episode>\d+)(?:\.)?(?<title>.*)$/i, # Show.S01E01.Title ; Show.S01.E01.Title ; Show S01 E01 Title /^(?<series>.*)(?:\.|\s+)?S(?<season>\d+)(?:\.|\s+)?E(?<episode>\d+)(?:\.|\s+)?(?<title>.*)$/i, # 1x1; 12x12 /^(?<series>.*)(?:\.)?(?<season>\d+)x(?<episode>\d+)(?:\.)?(?<title>.*)$/, # Show 01 - Title /^(?<series>.*)\s+(?<episode>\d{1,2})\s+-\s+(?<title>.+)$/, # [Show] 01 Episode /(?<series>.*)\s*(?<episode>\d{1,2})\s+(?<title>.+)$/, # 101; 1212 /^(?<series>.*\D)(?<season>\d+)(?<episode>\d{2})(?<title>\W*.*)$/, # TERRIBLE ONES ------------------------------------------------ # ^101$ /^(?<season>\d+)(?<episode>\d{2})$/ ].freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(string) ⇒ Object
Parse a given string and look for matches.
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
26 27 28 |
# File 'lib/showfix/parser.rb', line 26 def initialize(={}) @options = {}.merge() end |
Instance Method Details
#parse(string) ⇒ Object
Parse a given string and look for matches
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/showfix/parser.rb', line 31 def parse(string) matches = PATTERNS.map do |pattern| pattern.match(string) end.compact if matches.size > 0 matches.first else nil end end |