Module: Fixnames::Filters

Included in:
Engine
Defined in:
lib/fixnames/filters.rb

Instance Method Summary collapse

Instance Method Details

#and_to_dashObject



11
12
13
# File 'lib/fixnames/filters.rb', line 11

def and_to_dash
  replace '[-_ ]+and[-_ ]+', '-'
end

#bannersObject



20
21
22
23
24
# File 'lib/fixnames/filters.rb', line 20

def banners
  option.banner_types.each do |x|
    remove_bracket_ranges(x)
  end
end

#bracketsObject



26
27
28
29
30
31
32
33
34
# File 'lib/fixnames/filters.rb', line 26

def brackets
  bop = option.bracket_characters_open.dup
  bcl = option.bracket_characters_close.dup
  while bop.length > 0
    op = "%03o" % bop.slice!(0,1).bytes.first
    cl = "%03o" % bcl.slice!(0,1).bytes.first
    replace "\\#{op}(.+?)\\#{cl}", '-\\1-'
  end
end

#camelcaseObject



66
67
68
69
# File 'lib/fixnames/filters.rb', line 66

def camelcase
  replace '([a-z])([A-Z])', '\1_\2'
  fixed.downcase!
end

#charstrip(chrlist) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/fixnames/filters.rb', line 93

def charstrip(chrlist)
  re = Regexp.escape( if option.charstrip_allow_brackets
                        remove_bracket_characters_from(chrlist)
                      else
                        chrlist
                      end )
  remove "[#{re}]"
end

#checksumsObject



36
37
38
# File 'lib/fixnames/filters.rb', line 36

def checksums
  remove wrap_brackets('[0-9a-fA-F]{8}')
end

#expunge(re) ⇒ Object



3
4
5
# File 'lib/fixnames/filters.rb', line 3

def expunge(re)
  replace re, option.mendstr
end

#fix_dashesObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/fixnames/filters.rb', line 51

def fix_dashes
  fixed.squeeze! '-'
  replace_all '--', '-'

  remove_all  '^-'
  remove_all  '-$'

  replace_all '-\.', '.'
  replace_all '\.-', '.'
end

#fix_dotsObject



44
45
46
47
48
49
# File 'lib/fixnames/filters.rb', line 44

def fix_dots
  last = fixed.rindex('.')
  translate '.', '_'
  replace '(.*)\.(.*\.)', '\1_\2'
  fixed[last] = '.' if last
end

#fix_numsepObject



62
63
64
# File 'lib/fixnames/filters.rb', line 62

def fix_numsep
  replace '^(\d+)_', '\1-'
end

#hack_andObject



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

def hack_and
  replace '&', '_and_'
end

#junkwords(wordlist) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/fixnames/filters.rb', line 71

def junkwords(wordlist)
  wordlist.each do |word|
    replace "[_-]#{word}[_-]", '_'
    remove  "[_-]#{word}$"
    remove     "^#{word}[_-]"
  end
end

#lowercaseObject



40
41
42
# File 'lib/fixnames/filters.rb', line 40

def lowercase
  translate 'A-Z', 'a-z'
end

#semicolonObject



15
16
17
18
# File 'lib/fixnames/filters.rb', line 15

def semicolon
  translate ';', '-'
  fixed.squeeze! '-'
end

#whitespace(chrlist) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fixnames/filters.rb', line 79

def whitespace(chrlist)
  replace "[#{Regexp.escape chrlist}]", '_'

  remove_all '^_'
  remove_all '_$'

  replace_all  '_-', '-'
  replace_all  '-_', '-'
  replace_all '_\.', '.'
  replace_all '\._', '.'

  fixed.squeeze! '_'
end