fixnames 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/fixdirs +53 -22
- data/bin/fixnames +53 -22
- data/fixnames.gemspec +9 -3
- data/lib/fixnames/filters.rb +31 -8
- data/lib/fixnames/helpers.rb +15 -0
- data/lib/fixnames/option.rb +51 -13
- data/lib/fixnames/version.rb +2 -2
- data/spec/fixnames/and_to_dash_spec.rb +34 -0
- data/spec/fixnames/badopt_spec.rb +91 -0
- data/spec/fixnames/brackets_spec.rb +82 -6
- data/spec/fixnames/dashes_spec.rb +33 -0
- data/spec/fixnames/expunge_spec.rb +59 -0
- data/spec/fixnames/numsep_spec.rb +26 -0
- data/spec/fixnames/whitespace_spec.rb +14 -4
- data/spec/support/option_setting_helpers.rb +50 -0
- data/spec/support/should_fix_helpers.rb +8 -0
- metadata +54 -23
data/bin/fixdirs
CHANGED
@@ -29,76 +29,107 @@ optparse = OptionParser.new do |opts|
|
|
29
29
|
opts.separator 'DIRECTORIES:'
|
30
30
|
|
31
31
|
opts.on('-g', '--glob=GLOB_STRING',
|
32
|
-
|
32
|
+
"Filename glob to use inside each directory for when
|
33
33
|
#{desc_pad}we are left to ourself. Default: #{options.dir_glob}"
|
34
34
|
) { |val| options.dir_glob = val }
|
35
35
|
|
36
36
|
opts.on('-R', '--[no-]recursive',
|
37
|
-
|
37
|
+
'Recursively descend into directories'
|
38
38
|
) { |val| options.recursive = val }
|
39
39
|
|
40
40
|
opts.separator ''
|
41
41
|
opts.separator 'FILTERS:'
|
42
42
|
|
43
|
-
opts.on('-
|
44
|
-
|
43
|
+
opts.on('-H', '--[no-]hack-and',
|
44
|
+
'Replace "&" with "_and_"'
|
45
|
+
) { |val| options.hack_and = val }
|
46
|
+
|
47
|
+
opts.on('-A', '--[no-]and-to-dash',
|
48
|
+
'Replace "_and_" with "-"'
|
45
49
|
) { |val| options.hack_and = val }
|
46
50
|
|
47
51
|
opts.on('-C', '--[no-]semicolon',
|
48
|
-
|
52
|
+
'Replace ";" with "-"'
|
49
53
|
) { |val| options.semicolon = val }
|
50
54
|
|
51
55
|
opts.on('-B', '--[no-]banners',
|
52
|
-
|
56
|
+
'Trims [FOO] style advert prefixs from the beginning'
|
53
57
|
) { |val| options.banners = val }
|
54
58
|
|
55
|
-
opts.on('-b', '--[no-]brackets',
|
56
|
-
'Trims (round) or [square] bracket regions'
|
57
|
-
) { |val| options.brackets = val }
|
58
|
-
|
59
59
|
opts.on('-k', '--[no-]checksums',
|
60
|
-
|
60
|
+
"Trims [0A1B2C3D] CRC32 bracket-wrapped checksums
|
61
61
|
#{desc_pad}from names, when wrapped with square brackes []
|
62
62
|
#{desc_pad}or round parens ()"
|
63
63
|
) { |val| options.checksums = val }
|
64
64
|
|
65
65
|
opts.on('-d', '--[no-]dots',
|
66
|
-
|
66
|
+
'Trims excessive dots from files
|
67
67
|
(before the .extention)'
|
68
68
|
) { |val| options.fix_dots = val }
|
69
69
|
|
70
70
|
opts.on('-D', '--[no-]dashes',
|
71
|
-
|
71
|
+
'Trims redundant dashes, and leading/trailing dashes'
|
72
72
|
) { |val| options.fix_dashes = val }
|
73
73
|
|
74
|
+
opts.on('-N', '--[no-]numsep',
|
75
|
+
'Fixes the separator afterinitial numbers. That is,
|
76
|
+
#{desc_pad}it replaces ^(\d+)_ with ^(\d+)-"'
|
77
|
+
) { |val| options.fix_numsep = val }
|
78
|
+
|
74
79
|
opts.on('-c', '--[no-]camelcase',
|
75
|
-
|
80
|
+
'Undo camelCase with underscores. "aB" becomes "a_b"'
|
76
81
|
) { |val| options.camelcase = val }
|
77
82
|
|
78
83
|
opts.on('-l', '--[no-]lowercase',
|
79
|
-
|
84
|
+
'Forces all letters to lowercase'
|
80
85
|
) { |val| options.lowercase = val }
|
81
86
|
|
82
87
|
opts.separator ''
|
83
88
|
opts.separator 'CHARACTERS:'
|
84
89
|
|
90
|
+
opts.on('-b', '--[no-]brackets',
|
91
|
+
"Trims matching bracket, replacing with a \"-\" or
|
92
|
+
#{desc_pad}nothing if at the beginning of end of the name;
|
93
|
+
#{desc_pad}characters that count as a bracket defined with
|
94
|
+
#{desc_pad}the options --bracken-open and --br-close"
|
95
|
+
) { |val| options.brackets = val }
|
96
|
+
|
97
|
+
opts.on('-O', '--br-open=CHARS',
|
98
|
+
"Characters that count as the 'opening' half of a
|
99
|
+
#{desc_pad}bracket pair. Much be the same number of chars
|
100
|
+
#{desc_pad}as --br-close. The order in BOTH of these
|
101
|
+
#{desc_pad}options determines the pairing between open and
|
102
|
+
#{desc_pad}close, in a manner very similar tr(1).
|
103
|
+
#{desc_pad}Default: #{options.bracket_characters_close}"
|
104
|
+
) { |val| options.bracket_characters_open = val }
|
105
|
+
|
106
|
+
opts.on('-L', '--br-close=CHARS',
|
107
|
+
"Characters that count as the 'opening' half of a
|
108
|
+
#{desc_pad}bracket pair. Much be the same number of chars
|
109
|
+
#{desc_pad}as --br-close. The order in BOTH of these
|
110
|
+
#{desc_pad}options determines the pairing between open and
|
111
|
+
#{desc_pad}close, in a manner very similar tr(1).
|
112
|
+
#{desc_pad}Default: #{options.bracket_characters_close}"
|
113
|
+
) { |val| options.bracket_characters_close = val }
|
114
|
+
|
85
115
|
opts.on('-w', '--whitespace=CHARS',
|
86
|
-
|
116
|
+
"Characters to treat as whitespace, to be
|
87
117
|
#{desc_pad}replaced with underscores."
|
88
118
|
) { |val| options.whitespace = val }
|
89
119
|
|
90
120
|
opts.on('-W', '--no-whitespace',
|
91
|
-
|
121
|
+
'Do not parse any character as whitespace'
|
92
122
|
) { options.whitespace = nil }
|
93
123
|
|
94
|
-
opts.on('-s', '--strip=CHARLIST',
|
95
|
-
|
124
|
+
opts.on('-s', '--[no-]strip=CHARLIST',
|
125
|
+
"Individual characters to strip from names.
|
96
126
|
#{desc_pad}Default: #{options.charstrip}"
|
97
127
|
) { |val| options.charstrip = val }
|
98
128
|
|
99
|
-
opts.on('-
|
100
|
-
|
101
|
-
|
129
|
+
opts.on('-j', '--[no-]junkwords=WORDLIST',
|
130
|
+
"Words to always strip, separated by commas.
|
131
|
+
#{desc_pad}Default: #{options.junkwords.join(',')}"
|
132
|
+
) { options.junkwords = nil }
|
102
133
|
|
103
134
|
opts.separator ''
|
104
135
|
opts.separator 'REGEX-REPLACE:'
|
data/bin/fixnames
CHANGED
@@ -29,76 +29,107 @@ optparse = OptionParser.new do |opts|
|
|
29
29
|
opts.separator 'DIRECTORIES:'
|
30
30
|
|
31
31
|
opts.on('-g', '--glob=GLOB_STRING',
|
32
|
-
|
32
|
+
"Filename glob to use inside each directory for when
|
33
33
|
#{desc_pad}we are left to ourself. Default: #{options.dir_glob}"
|
34
34
|
) { |val| options.dir_glob = val }
|
35
35
|
|
36
36
|
opts.on('-R', '--[no-]recursive',
|
37
|
-
|
37
|
+
'Recursively descend into directories'
|
38
38
|
) { |val| options.recursive = val }
|
39
39
|
|
40
40
|
opts.separator ''
|
41
41
|
opts.separator 'FILTERS:'
|
42
42
|
|
43
|
-
opts.on('-
|
44
|
-
|
43
|
+
opts.on('-H', '--[no-]hack-and',
|
44
|
+
'Replace "&" with "_and_"'
|
45
|
+
) { |val| options.hack_and = val }
|
46
|
+
|
47
|
+
opts.on('-A', '--[no-]and-to-dash',
|
48
|
+
'Replace "_and_" with "-"'
|
45
49
|
) { |val| options.hack_and = val }
|
46
50
|
|
47
51
|
opts.on('-C', '--[no-]semicolon',
|
48
|
-
|
52
|
+
'Replace ";" with "-"'
|
49
53
|
) { |val| options.semicolon = val }
|
50
54
|
|
51
55
|
opts.on('-B', '--[no-]banners',
|
52
|
-
|
56
|
+
'Trims [FOO] style advert prefixs from the beginning'
|
53
57
|
) { |val| options.banners = val }
|
54
58
|
|
55
|
-
opts.on('-b', '--[no-]brackets',
|
56
|
-
'Trims (round) or [square] bracket regions'
|
57
|
-
) { |val| options.brackets = val }
|
58
|
-
|
59
59
|
opts.on('-k', '--[no-]checksums',
|
60
|
-
|
60
|
+
"Trims [0A1B2C3D] CRC32 bracket-wrapped checksums
|
61
61
|
#{desc_pad}from names, when wrapped with square brackes []
|
62
62
|
#{desc_pad}or round parens ()"
|
63
63
|
) { |val| options.checksums = val }
|
64
64
|
|
65
65
|
opts.on('-d', '--[no-]dots',
|
66
|
-
|
66
|
+
'Trims excessive dots from files
|
67
67
|
(before the .extention)'
|
68
68
|
) { |val| options.fix_dots = val }
|
69
69
|
|
70
70
|
opts.on('-D', '--[no-]dashes',
|
71
|
-
|
71
|
+
'Trims redundant dashes, and leading/trailing dashes'
|
72
72
|
) { |val| options.fix_dashes = val }
|
73
73
|
|
74
|
+
opts.on('-N', '--[no-]numsep',
|
75
|
+
'Fixes the separator afterinitial numbers. That is,
|
76
|
+
#{desc_pad}it replaces ^(\d+)_ with ^(\d+)-"'
|
77
|
+
) { |val| options.fix_numsep = val }
|
78
|
+
|
74
79
|
opts.on('-c', '--[no-]camelcase',
|
75
|
-
|
80
|
+
'Undo camelCase with underscores. "aB" becomes "a_b"'
|
76
81
|
) { |val| options.camelcase = val }
|
77
82
|
|
78
83
|
opts.on('-l', '--[no-]lowercase',
|
79
|
-
|
84
|
+
'Forces all letters to lowercase'
|
80
85
|
) { |val| options.lowercase = val }
|
81
86
|
|
82
87
|
opts.separator ''
|
83
88
|
opts.separator 'CHARACTERS:'
|
84
89
|
|
90
|
+
opts.on('-b', '--[no-]brackets',
|
91
|
+
"Trims matching bracket, replacing with a \"-\" or
|
92
|
+
#{desc_pad}nothing if at the beginning of end of the name;
|
93
|
+
#{desc_pad}characters that count as a bracket defined with
|
94
|
+
#{desc_pad}the options --bracken-open and --br-close"
|
95
|
+
) { |val| options.brackets = val }
|
96
|
+
|
97
|
+
opts.on('-O', '--br-open=CHARS',
|
98
|
+
"Characters that count as the 'opening' half of a
|
99
|
+
#{desc_pad}bracket pair. Much be the same number of chars
|
100
|
+
#{desc_pad}as --br-close. The order in BOTH of these
|
101
|
+
#{desc_pad}options determines the pairing between open and
|
102
|
+
#{desc_pad}close, in a manner very similar tr(1).
|
103
|
+
#{desc_pad}Default: #{options.bracket_characters_close}"
|
104
|
+
) { |val| options.bracket_characters_open = val }
|
105
|
+
|
106
|
+
opts.on('-L', '--br-close=CHARS',
|
107
|
+
"Characters that count as the 'opening' half of a
|
108
|
+
#{desc_pad}bracket pair. Much be the same number of chars
|
109
|
+
#{desc_pad}as --br-close. The order in BOTH of these
|
110
|
+
#{desc_pad}options determines the pairing between open and
|
111
|
+
#{desc_pad}close, in a manner very similar tr(1).
|
112
|
+
#{desc_pad}Default: #{options.bracket_characters_close}"
|
113
|
+
) { |val| options.bracket_characters_close = val }
|
114
|
+
|
85
115
|
opts.on('-w', '--whitespace=CHARS',
|
86
|
-
|
116
|
+
"Characters to treat as whitespace, to be
|
87
117
|
#{desc_pad}replaced with underscores."
|
88
118
|
) { |val| options.whitespace = val }
|
89
119
|
|
90
120
|
opts.on('-W', '--no-whitespace',
|
91
|
-
|
121
|
+
'Do not parse any character as whitespace'
|
92
122
|
) { options.whitespace = nil }
|
93
123
|
|
94
|
-
opts.on('-s', '--strip=CHARLIST',
|
95
|
-
|
124
|
+
opts.on('-s', '--[no-]strip=CHARLIST',
|
125
|
+
"Individual characters to strip from names.
|
96
126
|
#{desc_pad}Default: #{options.charstrip}"
|
97
127
|
) { |val| options.charstrip = val }
|
98
128
|
|
99
|
-
opts.on('-
|
100
|
-
|
101
|
-
|
129
|
+
opts.on('-j', '--[no-]junkwords=WORDLIST',
|
130
|
+
"Words to always strip, separated by commas.
|
131
|
+
#{desc_pad}Default: #{options.junkwords.join(',')}"
|
132
|
+
) { options.junkwords = nil }
|
102
133
|
|
103
134
|
opts.separator ''
|
104
135
|
opts.separator 'REGEX-REPLACE:'
|
data/fixnames.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fixnames"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brent Sanders"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-29"
|
13
13
|
s.description = "Cleans up filenames so they can easily be used\nin scripts, without annoyances such as spaces or other bad characters"
|
14
14
|
s.email = "git@thoughtnoise.net"
|
15
15
|
s.executables = ["fixnames", "fixdirs"]
|
@@ -36,17 +36,23 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/fixnames/interface.rb",
|
37
37
|
"lib/fixnames/option.rb",
|
38
38
|
"lib/fixnames/version.rb",
|
39
|
+
"spec/fixnames/and_to_dash_spec.rb",
|
40
|
+
"spec/fixnames/badopt_spec.rb",
|
39
41
|
"spec/fixnames/banners_spec.rb",
|
40
42
|
"spec/fixnames/brackets_spec.rb",
|
41
43
|
"spec/fixnames/camelcase_spec.rb",
|
42
44
|
"spec/fixnames/charstrip_spec.rb",
|
43
45
|
"spec/fixnames/checksums_spec.rb",
|
46
|
+
"spec/fixnames/dashes_spec.rb",
|
47
|
+
"spec/fixnames/expunge_spec.rb",
|
44
48
|
"spec/fixnames/fixdots_spec.rb",
|
45
49
|
"spec/fixnames/hack_and_spec.rb",
|
46
50
|
"spec/fixnames/lowercase_spec.rb",
|
51
|
+
"spec/fixnames/numsep_spec.rb",
|
47
52
|
"spec/fixnames/semicolon_spec.rb",
|
48
53
|
"spec/fixnames/whitespace_spec.rb",
|
49
54
|
"spec/spec_helper.rb",
|
55
|
+
"spec/support/option_setting_helpers.rb",
|
50
56
|
"spec/support/should_fix_helpers.rb",
|
51
57
|
"test/helper.rb",
|
52
58
|
"test/test_charstrip.rb",
|
@@ -58,7 +64,7 @@ Gem::Specification.new do |s|
|
|
58
64
|
s.homepage = "http://github.com/pdkl95/fixnames"
|
59
65
|
s.licenses = ["MIT"]
|
60
66
|
s.require_paths = ["lib"]
|
61
|
-
s.rubygems_version = "1.8.
|
67
|
+
s.rubygems_version = "1.8.23"
|
62
68
|
s.summary = "Filename cleanup for script compatability"
|
63
69
|
|
64
70
|
if s.respond_to? :specification_version then
|
data/lib/fixnames/filters.rb
CHANGED
@@ -8,6 +8,10 @@ module Fixnames
|
|
8
8
|
replace '&', '_and_'
|
9
9
|
end
|
10
10
|
|
11
|
+
def and_to_dash
|
12
|
+
replace '[-_ ]+and[-_ ]+', '-'
|
13
|
+
end
|
14
|
+
|
11
15
|
def semicolon
|
12
16
|
translate ';', '-'
|
13
17
|
fixed.squeeze! '-'
|
@@ -20,7 +24,13 @@ module Fixnames
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def brackets
|
23
|
-
|
27
|
+
bop = option.bracket_characters_open.dup
|
28
|
+
bcl = option.bracket_characters_close.dup
|
29
|
+
while bop.length > 0
|
30
|
+
op = "%03o" % bop.slice!(0,1).bytes.first
|
31
|
+
cl = "%03o" % bcl.slice!(0,1).bytes.first
|
32
|
+
replace "\\#{op}(.+?)\\#{cl}", '-\\1-'
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
def checksums
|
@@ -40,8 +50,17 @@ module Fixnames
|
|
40
50
|
|
41
51
|
def fix_dashes
|
42
52
|
fixed.squeeze! '-'
|
43
|
-
|
44
|
-
|
53
|
+
replace_all '--', '-'
|
54
|
+
|
55
|
+
remove_all '^-'
|
56
|
+
remove_all '-$'
|
57
|
+
|
58
|
+
replace_all '-\.', '.'
|
59
|
+
replace_all '\.-', '.'
|
60
|
+
end
|
61
|
+
|
62
|
+
def fix_numsep
|
63
|
+
replace '^(\d+)_', '\1-'
|
45
64
|
end
|
46
65
|
|
47
66
|
def camelcase
|
@@ -59,11 +78,15 @@ module Fixnames
|
|
59
78
|
|
60
79
|
def whitespace(chrlist)
|
61
80
|
replace "[#{Regexp.escape chrlist}]", '_'
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
81
|
+
|
82
|
+
remove_all '^_'
|
83
|
+
remove_all '_$'
|
84
|
+
|
85
|
+
replace_all '_-', '-'
|
86
|
+
replace_all '-_', '-'
|
87
|
+
replace_all '_\.', '.'
|
88
|
+
replace_all '\._', '.'
|
89
|
+
|
67
90
|
fixed.squeeze! '_'
|
68
91
|
end
|
69
92
|
|
data/lib/fixnames/helpers.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module Fixnames
|
2
2
|
module Helpers
|
3
|
+
def safeloop(condition, max_tries = option.max_filter_loops, &block)
|
4
|
+
max_tries.times do
|
5
|
+
return fixed unless fixed =~ Regexp.new(condition)
|
6
|
+
block.call
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
3
10
|
def replace(re, replacement)
|
4
11
|
re_str = bold "/#{re}/"
|
5
12
|
replacement_str = bold "\"#{replacement}\""
|
@@ -13,6 +20,14 @@ module Fixnames
|
|
13
20
|
fixed.gsub! Regexp.new(re), ''
|
14
21
|
end
|
15
22
|
|
23
|
+
def replace_all(condition, replacement)
|
24
|
+
safeloop(condition) { replace(condition, replacement) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove_all(condition)
|
28
|
+
safeloop(condition) { remove(condition) }
|
29
|
+
end
|
30
|
+
|
16
31
|
def translate(src, dst)
|
17
32
|
debug "\t<translate> #{bold src.inspect} -> #{bold dst.inspect}"
|
18
33
|
fixed.tr! src, dst
|
data/lib/fixnames/option.rb
CHANGED
@@ -2,30 +2,56 @@ require 'abbrev'
|
|
2
2
|
|
3
3
|
module Fixnames
|
4
4
|
class Option
|
5
|
+
# the maximum number of times we will allow a filter
|
6
|
+
# to be applied before giving up and moving on to the next
|
7
|
+
MAX_FILTER_LOOPS = 6
|
8
|
+
|
5
9
|
# filters that MUST run early
|
6
|
-
SETUP_FILTERS = [
|
10
|
+
SETUP_FILTERS = [
|
11
|
+
:expunge,
|
12
|
+
:brackets
|
13
|
+
]
|
7
14
|
|
8
15
|
# filters that only accept a simple boolean on/off
|
9
|
-
FLAG_FILTERS = [
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
FLAG_FILTERS = [
|
17
|
+
:hack_and,
|
18
|
+
:and_to_dash,
|
19
|
+
:checksums,
|
20
|
+
:banners,
|
21
|
+
:semicolon,
|
22
|
+
:camelcase,
|
23
|
+
:lowercase,
|
24
|
+
:fix_dots,
|
25
|
+
:fix_dashes,
|
26
|
+
:fix_numsep
|
27
|
+
]
|
13
28
|
|
14
29
|
# filters that accept character ranges
|
15
|
-
CHAR_FILTERS = [
|
30
|
+
CHAR_FILTERS = [
|
31
|
+
:junkwords,
|
32
|
+
:charstrip,
|
33
|
+
:whitespace
|
34
|
+
]
|
35
|
+
|
36
|
+
# filters that MUST run after everything else
|
37
|
+
LATE_FILTERS = [
|
38
|
+
:fix_numsep
|
39
|
+
]
|
16
40
|
|
17
41
|
# standard order to apply the filters
|
18
|
-
DEFAULT_FILTER_ORDER = [
|
19
|
-
|
20
|
-
|
21
|
-
|
42
|
+
DEFAULT_FILTER_ORDER = [
|
43
|
+
SETUP_FILTERS,
|
44
|
+
FLAG_FILTERS,
|
45
|
+
CHAR_FILTERS,
|
46
|
+
LATE_FILTERS
|
47
|
+
].flatten
|
22
48
|
|
23
49
|
DEFAULT_DIR_GLOB = '*'
|
24
50
|
DEFAULT_MENDSTR = ''
|
25
51
|
DEFAULT_WHITESPACE = " \t_"
|
26
52
|
DEFAULT_BRACKET_CHARACTERS_OPEN = '[({<'
|
27
53
|
DEFAULT_BRACKET_CHARACTERS_CLOSE = '])}>'
|
28
|
-
DEFAULT_CHARSTRIP = "[]{}'\",()
|
54
|
+
DEFAULT_CHARSTRIP = "[]{}'\",()+!~@#/\\<>"
|
29
55
|
DEFAULT_JUNKWORDS = [ 'x264', 'hdtv', '2hd', '720p', 'dvdrip']
|
30
56
|
DEFAULT_BANNER_TYPES = [ 'xxx', 'dvdrip', 'dual_audio',
|
31
57
|
'xvid', 'h264', 'divx' ]
|
@@ -40,6 +66,9 @@ module Fixnames
|
|
40
66
|
var = "@#{name}"
|
41
67
|
|
42
68
|
define_method "valid_for_#{name}?" do |value|
|
69
|
+
value = nil if value == false
|
70
|
+
return true if value.nil?
|
71
|
+
return true if value == ''
|
43
72
|
types.map do |type|
|
44
73
|
value.is_a?(type)
|
45
74
|
end.reduce(false) do |t,x|
|
@@ -53,7 +82,7 @@ module Fixnames
|
|
53
82
|
end
|
54
83
|
if args.length == 1
|
55
84
|
unless send("valid_for_#{name}?", args[0])
|
56
|
-
raise "bad type for option"
|
85
|
+
raise ArgumentError, "bad type for option"
|
57
86
|
end
|
58
87
|
instance_variable_set(var, args[0])
|
59
88
|
end
|
@@ -62,7 +91,7 @@ module Fixnames
|
|
62
91
|
|
63
92
|
define_method "#{name}=" do |value|
|
64
93
|
unless send("valid_for_#{name}?", value)
|
65
|
-
raise "bad type for option"
|
94
|
+
raise ArgumentError, "bad type for option"
|
66
95
|
end
|
67
96
|
instance_variable_set(var, value)
|
68
97
|
end
|
@@ -87,6 +116,9 @@ module Fixnames
|
|
87
116
|
# * `verbose=3` ; all *filters* are output as they run for debugging. Very noisy.
|
88
117
|
mkopt :verbose, Integer, 0
|
89
118
|
|
119
|
+
# @note The maximum number of times a {Fixname::Filters} will be applied before giving and proceeding with the next filter (infinite-loop protextion)
|
120
|
+
mkopt :max_filter_loops, Integer, MAX_FILTER_LOOPS
|
121
|
+
|
90
122
|
# When {#recursive} is set, use this pattern to glob each
|
91
123
|
# directory for files.
|
92
124
|
mkopt :dir_glob, String, DEFAULT_DIR_GLOB
|
@@ -104,6 +136,9 @@ module Fixnames
|
|
104
136
|
# @note Enables {Fixnames::Filters#hack_and}
|
105
137
|
mkopt :hack_and, [TrueClass, FalseClass], false
|
106
138
|
|
139
|
+
# @note Enables {Fixnames::Filters#hack_and}
|
140
|
+
mkopt :and_to_dash, [TrueClass, FalseClass], false
|
141
|
+
|
107
142
|
# @note Enables {Fixnames::Filters#checksums}
|
108
143
|
mkopt :checksums, [TrueClass, FalseClass], false
|
109
144
|
|
@@ -122,6 +157,9 @@ module Fixnames
|
|
122
157
|
# @note Enables {Fixnames::Filters#fix_dashes}
|
123
158
|
mkopt :fix_dashes, [TrueClass, FalseClass], false
|
124
159
|
|
160
|
+
# @note Enables {Fixnames::Filters#fix_dashes}
|
161
|
+
mkopt :fix_numsep, [TrueClass, FalseClass], false
|
162
|
+
|
125
163
|
# @note Enables {Fixnames::Filters#camelcase}
|
126
164
|
mkopt :camelcase, [TrueClass, FalseClass], false
|
127
165
|
|
data/lib/fixnames/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Fixnames do
|
4
|
+
context "when option[:and_to_dash] is TRUE" do
|
5
|
+
before do
|
6
|
+
@testopt.and_to_dash = true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "should replace \"_and_\" with \"-\"" do
|
10
|
+
subject { 'a-b' }
|
11
|
+
it_should_fix 'a_and_b', 'a and b', 'a-and-b'
|
12
|
+
it_should_fix 'a-and_b', 'a_and-b'
|
13
|
+
it_should_fix 'a-and b', 'a and-b'
|
14
|
+
it_should_fix 'a and_b', 'a_and b'
|
15
|
+
|
16
|
+
it_should_fix 'a and b'
|
17
|
+
it_should_fix 'a- -and- -b'
|
18
|
+
it_should_fix 'a- _and_ -b'
|
19
|
+
it_should_fix 'a__and__b'
|
20
|
+
it_should_fix 'a_-_and_-_b'
|
21
|
+
it_should_fix 'a - and - b'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when option[:and_to_dash] is FALSE" do
|
26
|
+
before do
|
27
|
+
@testopt.and_to_dash = false
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "should replace ALLOW \"&\"" do
|
31
|
+
it_should_not_change 'a_and_b'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Fixnames::Option do
|
4
|
+
context "when setting new options" do
|
5
|
+
describe "should allow bool types" do
|
6
|
+
it_should_allow_bool_option 'recursive'
|
7
|
+
it_should_allow_bool_option 'hack_and'
|
8
|
+
it_should_allow_bool_option 'and_to_dash'
|
9
|
+
it_should_allow_bool_option 'checksums'
|
10
|
+
it_should_allow_bool_option 'banners'
|
11
|
+
it_should_allow_bool_option 'brackets'
|
12
|
+
it_should_allow_bool_option 'semicolon'
|
13
|
+
it_should_allow_bool_option 'fix_dots'
|
14
|
+
it_should_allow_bool_option 'fix_dashes'
|
15
|
+
it_should_allow_bool_option 'fix_numsep'
|
16
|
+
it_should_allow_bool_option 'camelcase'
|
17
|
+
it_should_allow_bool_option 'lowercase'
|
18
|
+
it_should_allow_bool_option 'charstrip_allow_brackets'
|
19
|
+
it_should_allow_bool_option 'pretend'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "should allow integer types" do
|
23
|
+
it_should_allow_option 'max_filter_loops', 10
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "should allow string types" do
|
27
|
+
it_should_allow_option 'dir_glob', '*foo*'
|
28
|
+
it_should_allow_option 'expunge', '^(\d\d+)'
|
29
|
+
it_should_allow_option 'mendstr', '\1-'
|
30
|
+
it_should_allow_option 'charstrip', '!@#$%^&()_+-='
|
31
|
+
it_should_allow_option 'whitespace', " \t\n"
|
32
|
+
it_should_allow_option 'bracket_characters_open', "`\\"
|
33
|
+
it_should_allow_option 'bracket_characters_close', "'/"
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "should allow array types" do
|
37
|
+
it_should_allow_option 'junkwords', ['foo','bar','baz']
|
38
|
+
it_should_allow_option 'banner_types', ['foo','bar','baz']
|
39
|
+
it_should_allow_option 'filter_order', Fixnames::Option::DEFAULT_FILTER_ORDER.sort
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "should reject invalid non-bool types for bool options" do
|
43
|
+
[ 'recursive',
|
44
|
+
'hack_and',
|
45
|
+
'and_to_dash',
|
46
|
+
'checksums',
|
47
|
+
'banners',
|
48
|
+
'brackets',
|
49
|
+
'semicolon',
|
50
|
+
'fix_dots',
|
51
|
+
'fix_dashes',
|
52
|
+
'fix_numsep',
|
53
|
+
'camelcase',
|
54
|
+
'lowercase',
|
55
|
+
'charstrip_allow_brackets',
|
56
|
+
'pretend'
|
57
|
+
].each do |opt_name|
|
58
|
+
it_should_reject_nonbool_option(opt_name)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "should reject invalid non-integer types for integer options" do
|
63
|
+
[ 'max_filter_loops'
|
64
|
+
].each do |opt_name|
|
65
|
+
it_should_reject_noninteger_option(opt_name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "should reject invalid non-string types for string options" do
|
70
|
+
[ 'dir_glob',
|
71
|
+
'expunge',
|
72
|
+
'mendstr',
|
73
|
+
'charstrip',
|
74
|
+
'whitespace',
|
75
|
+
'bracket_characters_open',
|
76
|
+
'bracket_characters_close'
|
77
|
+
].each do |opt_name|
|
78
|
+
it_should_reject_nonstring_option(opt_name)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "should reject invalid non-array types for array options" do
|
83
|
+
[ 'junkwords',
|
84
|
+
'banner_types',
|
85
|
+
'filter_order'
|
86
|
+
].each do |opt_name|
|
87
|
+
it_should_reject_nonarray_option(opt_name)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,26 +1,102 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe Fixnames do
|
4
|
+
|
5
|
+
##########################################################################
|
4
6
|
context "when option[:brackets] is TRUE" do
|
5
7
|
before do
|
6
8
|
@testopt.brackets = true
|
9
|
+
@testopt.fix_dashes = true
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "should replace bracket pairs with a dash" do
|
13
|
+
subject { 'foo-x-bar' }
|
14
|
+
it_should_fix 'foo[x]bar'
|
15
|
+
it_should_fix 'foo[ x ]bar'
|
16
|
+
it_should_fix 'foo[-x-]bar'
|
17
|
+
it_should_fix 'foo[_x_]bar'
|
18
|
+
it_should_fix 'foo [x] bar'
|
19
|
+
it_should_fix 'foo-[x]-bar'
|
20
|
+
it_should_fix 'foo_[x]_bar'
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "should replace multiple bracket pairs" do
|
24
|
+
subject { 'foo-bar-baz-quux' }
|
25
|
+
it_should_fix 'foo(bar)baz<quux>'
|
26
|
+
it_should_fix 'foo(bar)[baz]quux'
|
27
|
+
it_should_fix 'foo(-bar-)baz<_quux_>'
|
28
|
+
it_should_fix 'foo-(bar)-baz-<quux>'
|
29
|
+
it_should_fix 'foo (bar) baz <quux>'
|
30
|
+
it_should_fix '{ foo }-( bar )-[ baz ]-< quux >'
|
31
|
+
it_should_fix '[ foo ]<->[ bar ]<->[ baz ]<->[ quux ]'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
##########################################################################
|
36
|
+
context "when option[:brackets] is FALSE and option[:charstrip] strips brackets" do
|
37
|
+
before do
|
38
|
+
@testopt.brackets = false
|
39
|
+
@testopt.charstrip_allow_brackets = false
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "should strip a single bracket pair" do
|
43
|
+
subject { 'fooxbar' }
|
44
|
+
it_should_fix 'foo[x]bar'
|
45
|
+
it_should_fix 'foo(x)bar'
|
46
|
+
it_should_fix 'foo<x>bar'
|
47
|
+
it_should_fix '[foo]xbar'
|
48
|
+
it_should_fix 'fooxba[r]'
|
49
|
+
it_should_fix '[fooxbar]'
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "should strip a single bracket pair near dashes" do
|
53
|
+
subject { 'foo-x-bar' }
|
54
|
+
it_should_fix 'foo[-x-]bar'
|
55
|
+
it_should_fix 'foo-[x]-bar'
|
56
|
+
it_should_fix '[foo]-x-bar'
|
57
|
+
it_should_fix '[foo-x-]bar'
|
58
|
+
it_should_fix 'foo-x[-bar]'
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "should strip a single bracket pair near undebars" do
|
62
|
+
subject { 'foo_x_bar' }
|
63
|
+
it_should_fix 'foo[_x_]bar'
|
64
|
+
it_should_fix 'foo_[x]_bar'
|
65
|
+
it_should_fix '[foo_]x_bar'
|
66
|
+
it_should_fix 'foo[_x_bar]'
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "should strip multiple bracket pairs" do
|
70
|
+
subject { 'foobarbazquux' }
|
71
|
+
it_should_fix 'foo(bar)baz[quux]'
|
72
|
+
it_should_fix '{foo}(bar)<baz>[quux]'
|
7
73
|
end
|
8
74
|
|
9
|
-
describe "should
|
10
|
-
subject { '
|
11
|
-
it_should_fix 'foo
|
12
|
-
it_should_fix 'foo
|
75
|
+
describe "should strip multiple brack pairs with dashes" do
|
76
|
+
subject { 'foo-bar-baz-quux' }
|
77
|
+
it_should_fix 'foo-bar-baz-quux'
|
78
|
+
it_should_fix 'foo-(b)ar-[baz-]quux'
|
79
|
+
it_should_fix 'foo<->bar[-]baz(-)quux'
|
80
|
+
it_should_fix '[foo]-[bar]-[baz]-[quux]'
|
13
81
|
end
|
14
82
|
end
|
15
83
|
|
16
|
-
|
84
|
+
##########################################################################
|
85
|
+
context "when option[:brackets] is FALSE and option[:charstrip] sllows brackets" do
|
17
86
|
before do
|
18
87
|
@testopt.brackets = false
|
19
88
|
@testopt.charstrip_allow_brackets = true
|
20
89
|
end
|
21
90
|
|
22
91
|
describe "should replace ALLOW bracket expressions" do
|
23
|
-
it_should_not_change 'foo[x]bar'
|
92
|
+
it_should_not_change 'foo[x]bar'
|
93
|
+
it_should_not_change 'foo[-x-]bar'
|
94
|
+
it_should_not_change 'foo[_x_]bar'
|
95
|
+
it_should_not_change 'foo-[x]-bar'
|
96
|
+
it_should_not_change 'foo_[x]_bar'
|
97
|
+
it_should_not_change 'fo(foo)ob<bar>ar'
|
98
|
+
it_should_not_change 'fo(-foo-)ob<_bar_>ar'
|
99
|
+
it_should_not_change 'fo-(foo)-ob-<bar>-ar'
|
24
100
|
end
|
25
101
|
end
|
26
102
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Fixnames do
|
4
|
+
context "when only option[:dashes] is non-nil" do
|
5
|
+
before do
|
6
|
+
@testopt.fix_dashes = true
|
7
|
+
@testopt.whitespace = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "should preserve single dashes between letters" do
|
11
|
+
it_should_not_change 'a-b'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should pass single underscores unchanged" do
|
15
|
+
it_should_not_change 'a_b'
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "should not duplicate the :whitesapce filter and collapse dashe-underscores pairs to a dash" do
|
19
|
+
it_should_not_change 'a-_b', 'a_-b', 'a_-_b'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "should collapse multiple dashes to a single character" do
|
23
|
+
subject { 'a-b' }
|
24
|
+
it_should_fix 'a--b', 'a---b', 'a----b'
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "should remove dashes near a dot" do
|
28
|
+
subject { 'a.b' }
|
29
|
+
it_should_fix 'a-.b', 'a.-b', 'a-.-b'
|
30
|
+
it_should_fix 'a--.b', 'a.--b', 'a--.--b'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Fixnames do
|
4
|
+
context "when option[:expunge] is Regexp-formatted string and option[:replace is nil" do
|
5
|
+
before do
|
6
|
+
@testopt.mendstr = Fixnames::Option::DEFAULT_MENDSTR
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "should erase matched fragments" do
|
10
|
+
subject { 'foo-242-bar-baz.quux' }
|
11
|
+
it_should_expunge_and_match '-', 'foo242barbaz.quux'
|
12
|
+
it_should_expunge_and_match 'b', 'foo-242-ar-az.quux'
|
13
|
+
it_should_expunge_and_match '\d+', 'foo--bar-baz.quux'
|
14
|
+
it_should_expunge_and_match '[0-9]+', 'foo--bar-baz.quux'
|
15
|
+
it_should_expunge_and_match '-.*-', 'foobaz.quux'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when options[:expunge] is a Regexp and ootions[:replace] is a string" do
|
20
|
+
before do
|
21
|
+
@testopt.mendstr = 'X'
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "should replace matched fragments" do
|
25
|
+
subject { 'foo-242-bar-baz.quux' }
|
26
|
+
it_should_expunge_and_match '-', 'fooX242XbarXbaz.quux'
|
27
|
+
it_should_expunge_and_match 'b', 'foo-242-Xar-Xaz.quux'
|
28
|
+
it_should_expunge_and_match '\d+', 'foo-X-bar-baz.quux'
|
29
|
+
it_should_expunge_and_match '[0-9]+', 'foo-X-bar-baz.quux'
|
30
|
+
it_should_expunge_and_match '-.*-', 'fooXbaz.quux'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when options[:expunge] is a Regexp and ootions[:replace] is a string with a backreference" do
|
35
|
+
before do
|
36
|
+
@testopt.mendstr = '\1-PLUGH'
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "should replace matched fragments (including backreferences)" do
|
40
|
+
subject { 'foo-242-bar-baz.quux' }
|
41
|
+
it_should_expunge_and_match 'foo-(\d+)', '242-PLUGH-bar-baz.quux'
|
42
|
+
it_should_expunge_and_match '(b\w*)', 'foo-242-bar-PLUGH-baz-PLUGH.quux'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when options[:expunge] is a Regexp and ootions[:replace] is a string with multiple backreferences" do
|
47
|
+
before do
|
48
|
+
@testopt.mendstr = '_\1\2\1_'
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "should replace matched fragments (including backreferences)" do
|
52
|
+
subject { 'foo-242-bar-baz.quux' }
|
53
|
+
it_should_expunge_and_match '(\d+)-(b\w*)', 'foo-242bar242-baz.quux'
|
54
|
+
it_should_expunge_and_match '-(\d+)-(b\w*)-', 'foo_242bar242_baz.quux'
|
55
|
+
it_should_expunge_and_match '(b)(\w\w)', 'foo-242-barb-bazb.quux'
|
56
|
+
it_should_expunge_and_match '-(b)(\w\w)-', 'foo-242_barb_baz.quux'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Fixnames do
|
4
|
+
context "when option[:fix_numsep] is TRUE" do
|
5
|
+
before do
|
6
|
+
@testopt.fix_numsep = true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "should replace \"_\" with \"-\" after leading digits" do
|
10
|
+
subject { '42-foo_bar-3_quux.baz' }
|
11
|
+
it_should_fix '42_foo_bar-3_quux.baz'
|
12
|
+
it_should_not_change 'prefix-42_foo_bar-3_quux.baz'
|
13
|
+
it_should_not_change 'prefix_42_foo_bar-3_quux.baz'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when option[:fix_numsep] is FALSE" do
|
18
|
+
before do
|
19
|
+
@testopt.fix_numsep = false
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "should not replace \"_\" with \"-\" after leading digits" do
|
23
|
+
it_should_not_change '42_foo_bar-3_quux.baz'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe Fixnames do
|
4
|
-
context "when option[:whitespace] is non-nil" do
|
4
|
+
context "when only option[:whitespace] is non-nil" do
|
5
|
+
before do
|
6
|
+
@testopt.fix_dashes = false
|
7
|
+
@testopt.whitespace = Fixnames::Option::DEFAULT_WHITESPACE
|
8
|
+
end
|
9
|
+
|
5
10
|
describe "should preserve simple names" do
|
6
11
|
it_should_not_change 'abc', 'a-b', 'a.b'
|
7
12
|
end
|
@@ -25,6 +30,11 @@ describe Fixnames do
|
|
25
30
|
it_should_fix 'a b', 'a b', 'a b'
|
26
31
|
end
|
27
32
|
|
33
|
+
describe "should collapse dash-underscore pairs to a dash" do
|
34
|
+
subject { 'a-b' }
|
35
|
+
it_should_fix 'a-_b', 'a_-b', 'a_-_b'
|
36
|
+
end
|
37
|
+
|
28
38
|
describe "should collapse multiple underscores to a single character" do
|
29
39
|
subject { 'a_b' }
|
30
40
|
it_should_fix 'a__b', 'a___b', 'a____b'
|
@@ -51,9 +61,9 @@ describe Fixnames do
|
|
51
61
|
|
52
62
|
describe "should remove whitespace preceding a dot" do
|
53
63
|
subject { 'a.b' }
|
54
|
-
it_should_fix 'a .b', 'a_.b'
|
55
|
-
it_should_fix 'a .b', 'a _.b'
|
56
|
-
it_should_fix 'a__.b', 'a _ .b'
|
64
|
+
it_should_fix 'a .b', 'a_.b'
|
65
|
+
it_should_fix 'a .b', 'a _.b'
|
66
|
+
it_should_fix 'a__.b', 'a _ .b'
|
57
67
|
end
|
58
68
|
|
59
69
|
describe "should remove whitespace around a single dash" do
|
@@ -0,0 +1,50 @@
|
|
1
|
+
def it_should_allow_option(opt_name, value)
|
2
|
+
specify "new value allowd: option.#{opt_name}(#{value.inspect})" do
|
3
|
+
expect do
|
4
|
+
@testopt.send(opt_name, value)
|
5
|
+
end.not_to raise_error(ArgumentError)
|
6
|
+
end
|
7
|
+
specify "new value allowd: option.#{opt_name} = #{value.inspect}" do
|
8
|
+
expect do
|
9
|
+
@testopt.send("#{opt_name}=", value)
|
10
|
+
end.not_to raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def it_should_allow_bool_option(opt_name)
|
15
|
+
it_should_allow_option(opt_name, true)
|
16
|
+
it_should_allow_option(opt_name, false)
|
17
|
+
end
|
18
|
+
|
19
|
+
def it_should_reject_option(opt_name, *values)
|
20
|
+
values.each do |value|
|
21
|
+
specify "new value rejected: option.#{opt_name}(#{value.inspect})" do
|
22
|
+
expect do
|
23
|
+
@testopt.send(opt_name, value)
|
24
|
+
end.to raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
specify "new value rejected: option.#{opt_name} = #{value.inspect}" do
|
27
|
+
expect do
|
28
|
+
@testopt.send("#{opt_name}=", value)
|
29
|
+
end.to raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def it_should_reject_nonbool_option(opt_name)
|
36
|
+
it_should_reject_option opt_name, 123, 'foo', ['foo','bar','baz']
|
37
|
+
end
|
38
|
+
|
39
|
+
def it_should_reject_noninteger_option(opt_name)
|
40
|
+
it_should_reject_option opt_name, true, 'foo', ['foo','bar','baz']
|
41
|
+
end
|
42
|
+
|
43
|
+
def it_should_reject_nonstring_option(opt_name)
|
44
|
+
it_should_reject_option opt_name, true, 123, ['foo','bar','baz']
|
45
|
+
end
|
46
|
+
|
47
|
+
def it_should_reject_nonarray_option(opt_name)
|
48
|
+
it_should_reject_option opt_name, true, 123, 'foo'
|
49
|
+
end
|
50
|
+
|
@@ -17,3 +17,11 @@ def it_should_fix(*args)
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def it_should_expunge_and_match(re, result)
|
22
|
+
specify "expunges /#{re}/ from #{subject.call.inspect} to produce #{result.inspect}" do
|
23
|
+
@testopt.expunge = re
|
24
|
+
fixed_for(subject).should eq(result)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixnames
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,63 +9,88 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
15
16
|
name: term-ansicolor
|
16
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.6
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
26
|
requirements:
|
19
27
|
- - ! '>='
|
20
28
|
- !ruby/object:Gem::Version
|
21
29
|
version: 1.0.6
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: *10551560
|
25
30
|
- !ruby/object:Gem::Dependency
|
31
|
+
type: :development
|
26
32
|
name: yard
|
27
|
-
|
33
|
+
prerelease: false
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.6.0
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
41
|
none: false
|
29
42
|
requirements:
|
30
43
|
- - ! '>='
|
31
44
|
- !ruby/object:Gem::Version
|
32
45
|
version: 0.6.0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *10550940
|
36
46
|
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
37
48
|
name: rspec
|
38
|
-
|
49
|
+
prerelease: false
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
57
|
none: false
|
40
58
|
requirements:
|
41
59
|
- - ! '>='
|
42
60
|
- !ruby/object:Gem::Version
|
43
61
|
version: 2.3.0
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *10532580
|
47
62
|
- !ruby/object:Gem::Dependency
|
63
|
+
type: :development
|
48
64
|
name: jeweler
|
49
|
-
|
65
|
+
prerelease: false
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.6.4
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
73
|
none: false
|
51
74
|
requirements:
|
52
75
|
- - ! '>='
|
53
76
|
- !ruby/object:Gem::Version
|
54
77
|
version: 1.6.4
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *10531940
|
58
78
|
- !ruby/object:Gem::Dependency
|
79
|
+
type: :development
|
59
80
|
name: simplecov
|
60
|
-
|
81
|
+
prerelease: false
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
89
|
none: false
|
62
90
|
requirements:
|
63
91
|
- - ! '>='
|
64
92
|
- !ruby/object:Gem::Version
|
65
93
|
version: '0'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *10531260
|
69
94
|
description: ! 'Cleans up filenames so they can easily be used
|
70
95
|
|
71
96
|
in scripts, without annoyances such as spaces or other bad characters'
|
@@ -96,17 +121,23 @@ files:
|
|
96
121
|
- lib/fixnames/interface.rb
|
97
122
|
- lib/fixnames/option.rb
|
98
123
|
- lib/fixnames/version.rb
|
124
|
+
- spec/fixnames/and_to_dash_spec.rb
|
125
|
+
- spec/fixnames/badopt_spec.rb
|
99
126
|
- spec/fixnames/banners_spec.rb
|
100
127
|
- spec/fixnames/brackets_spec.rb
|
101
128
|
- spec/fixnames/camelcase_spec.rb
|
102
129
|
- spec/fixnames/charstrip_spec.rb
|
103
130
|
- spec/fixnames/checksums_spec.rb
|
131
|
+
- spec/fixnames/dashes_spec.rb
|
132
|
+
- spec/fixnames/expunge_spec.rb
|
104
133
|
- spec/fixnames/fixdots_spec.rb
|
105
134
|
- spec/fixnames/hack_and_spec.rb
|
106
135
|
- spec/fixnames/lowercase_spec.rb
|
136
|
+
- spec/fixnames/numsep_spec.rb
|
107
137
|
- spec/fixnames/semicolon_spec.rb
|
108
138
|
- spec/fixnames/whitespace_spec.rb
|
109
139
|
- spec/spec_helper.rb
|
140
|
+
- spec/support/option_setting_helpers.rb
|
110
141
|
- spec/support/should_fix_helpers.rb
|
111
142
|
- test/helper.rb
|
112
143
|
- test/test_charstrip.rb
|
@@ -135,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
166
|
version: '0'
|
136
167
|
requirements: []
|
137
168
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.8.
|
169
|
+
rubygems_version: 1.8.23
|
139
170
|
signing_key:
|
140
171
|
specification_version: 3
|
141
172
|
summary: Filename cleanup for script compatability
|