Class: Mvtk::NameCleaner
- Inherits:
-
Object
- Object
- Mvtk::NameCleaner
- Defined in:
- lib/mvtk/namecleaner.rb
Instance Attribute Summary collapse
-
#clean_name ⇒ Object
Returns the value of attribute clean_name.
-
#raw_name ⇒ Object
Returns the value of attribute raw_name.
Class Method Summary collapse
Instance Method Summary collapse
- #clean ⇒ Object
- #clean_punctuation ⇒ Object
- #filetype ⇒ Object
-
#initialize(raw_name) ⇒ NameCleaner
constructor
A new instance of NameCleaner.
- #release_year ⇒ Object
- #remove_release_year ⇒ Object
- #remove_whitespace ⇒ Object
- #video_types ⇒ Object
Constructor Details
#initialize(raw_name) ⇒ NameCleaner
Returns a new instance of NameCleaner.
6 7 8 9 |
# File 'lib/mvtk/namecleaner.rb', line 6 def initialize(raw_name) @raw_name = raw_name @clean_name = raw_name end |
Instance Attribute Details
#clean_name ⇒ Object
Returns the value of attribute clean_name.
4 5 6 |
# File 'lib/mvtk/namecleaner.rb', line 4 def clean_name @clean_name end |
#raw_name ⇒ Object
Returns the value of attribute raw_name.
4 5 6 |
# File 'lib/mvtk/namecleaner.rb', line 4 def raw_name @raw_name end |
Class Method Details
.video_types_terms ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mvtk/namecleaner.rb', line 68 def self.video_types_terms [ { :name => "dvdrip", :modifier => Regexp::IGNORECASE }, { :name => "xvid", :modifier => Regexp::IGNORECASE }, { :name => "720p", :modifier => Regexp::IGNORECASE }, { :name => "1080p", :modifier => Regexp::IGNORECASE }, { :name => "x264", :modifier => Regexp::IGNORECASE }, { :name => "bluray", :modifier => Regexp::IGNORECASE }, { :name => "bdrip", :modifier => Regexp::IGNORECASE }, { :name => "multi", :modifier => Regexp::IGNORECASE }, { :name => "repack", :modifier => Regexp::IGNORECASE }, { :name => "aac", :modifier => Regexp::IGNORECASE }, { :name => "5.1", :modifier => Regexp::IGNORECASE }, { :name => "ac3", :modifier => Regexp::IGNORECASE }, { :name => "DTS", :modifier => Regexp::IGNORECASE }, { :name => "truefrench", :modifier => Regexp::IGNORECASE }, { :name => "french", :modifier => Regexp::IGNORECASE }, { :name => "www.cpasbien.cm", :modifier => Regexp::IGNORECASE } ] end |
Instance Method Details
#clean ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/mvtk/namecleaner.rb', line 47 def clean remove_release_year remove_video_types remove_filetype clean_punctuation remove_whitespace end |
#clean_punctuation ⇒ Object
11 12 13 14 |
# File 'lib/mvtk/namecleaner.rb', line 11 def clean_punctuation punctuation_to_remove = /[\.\[\]\(\)-]/ @clean_name = @clean_name.gsub(punctuation_to_remove, " ") end |
#filetype ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/mvtk/namecleaner.rb', line 101 def filetype filetypes = ["avi", "mp4", "mkv"] filetypes.find do |filetype| regexp = Regexp.new "\.#{filetype}" @raw_name.match regexp end end |
#release_year ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mvtk/namecleaner.rb', line 55 def release_year year_matches = @raw_name.scan(/(\d{4})/).flatten two_years_from_now= Time.now.strftime("%Y").to_i + 2 year_matches = year_matches.map { |year_match| year = year_match.to_i }.select { |year_match| (1895..two_years_from_now).include? year_match } year_matches.first if year_matches.size == 1 end |
#remove_release_year ⇒ Object
16 17 18 |
# File 'lib/mvtk/namecleaner.rb', line 16 def remove_release_year @clean_name = @clean_name.gsub(release_year.to_s, "") end |
#remove_whitespace ⇒ Object
42 43 44 45 |
# File 'lib/mvtk/namecleaner.rb', line 42 def remove_whitespace @clean_name = @clean_name.gsub(/\s+/, " ") @clean_name = @clean_name.strip end |
#video_types ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mvtk/namecleaner.rb', line 89 def video_types video_type = [] NameCleaner.video_types_terms.each_with_index do |term, index| regexp = term[:name] modifier = term[:modifier] video_type << index if @raw_name.match Regexp.new regexp, modifier # case insensitive end video_type end |