Module: Propre

Defined in:
lib/propre.rb

Class Method Summary collapse

Class Method Details

.ban_chars(arg) ⇒ Object



37
38
39
# File 'lib/propre.rb', line 37

def self.ban_chars(arg)
  arg.tr('^A-Za-z0-9 ', '').strip
end

.ban_words(arg) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/propre.rb', line 41

def self.ban_words(arg)
  arg.split.each do |word|
    Blacklist::WORDS.select do |e|
      arg.slice! word if word.include? e
    end
  end
  arg.squeeze(' ')
end

.basename_newname_metadata(arg) ⇒ Object



68
69
70
71
# File 'lib/propre.rb', line 68

def self.(arg)
  basename = File.basename(arg, File.extname(arg))
  [basename, format(propify(basename), (basename)), (basename)]
end

.find_episode(arg) ⇒ Object



21
22
23
24
# File 'lib/propre.rb', line 21

def self.find_episode(arg)
  arg = arg.match '(s\d{1,2}e\d{2,3})'
  arg.to_s
end

.find_urls(arg) ⇒ Object



11
12
13
14
# File 'lib/propre.rb', line 11

def self.find_urls(arg)
  arg = arg.match '((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)'
  arg.to_s
end

.find_years(arg) ⇒ Object



16
17
18
19
# File 'lib/propre.rb', line 16

def self.find_years(arg)
  arg = arg.match '((19|20)\d\d)'
  arg.to_s
end

.format(newname, metadata) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/propre.rb', line 59

def self.format(newname, )
  [:newname] = newname
  [:year] = "(#{[:year]})" unless [:year].empty?

  format = '%{newname} %{episode} %{year}'
  formated = format % 
  formated.strip.squeeze(' ')
end

.metadata(arg) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/propre.rb', line 50

def self.(arg)
  arg = arg.downcase
  {
    year: find_years(arg),
    episode: find_episode(arg).upcase,
    website: find_urls(arg)
  }
end

.propify(arg) ⇒ Object



7
8
9
# File 'lib/propre.rb', line 7

def self.propify(arg)
  ban_words(ban_chars(sanitize(remove_patterns(arg.downcase)))).split.map(&:capitalize).join(' ')
end

.remove_patterns(arg) ⇒ Object



26
27
28
29
30
31
# File 'lib/propre.rb', line 26

def self.remove_patterns(arg)
  arg.slice! find_urls(arg)
  arg.slice! find_years(arg)
  arg.slice! find_episode(arg)
  arg
end

.sanitize(arg) ⇒ Object



33
34
35
# File 'lib/propre.rb', line 33

def self.sanitize(arg)
  arg.gsub('.', ' ').strip
end