mundane 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/bin/mundane +8 -1
- data/lib/mundane.rb +6 -1
- data/lib/mundane/algos/ban_from_name.rb +41 -0
- data/lib/mundane/version.rb +1 -1
- data/spec/spec_helper.rb +9 -1
- data/spec/unit/mundane_spec.rb +35 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MThiY2U3ZDljZTAwNmJkOTRjMzc2N2JkNzQ5MGRiN2FkMGE1ZDZlYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTkzNTY4YTQ3MDhlOGI0N2FjMGFhNGJkZjE1M2Q1ZTJkZTA3M2NmYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTNmM2UxNjUzMjQ5ZTRjNDViZjBhMzM0YjMyMGI0ZGFhYjQ0NWJlZTVjMzRh
|
10
|
+
NmMwMGRhZjQzNmNkMTY3NGE3ZjA5ZmQ0NzZkZTcwZmMxMDMwYzllZjdhYWJm
|
11
|
+
ZDViYzBkMzM2N2UxZTYyYWRkNTRhZTcxMjc1YzE2NWUyZTkwMGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmE2ZTRiNzM5M2RiZDk4MmQxZDYzMmM1NDNkNzcwNTk2NzU0Y2JlNjNiNTIw
|
14
|
+
MjEzYWRhMTAxNjUxYjkxZjQxMjVhNzcyZDg4MTY3YWI5ZWRhNjg3MmE3ZjVh
|
15
|
+
NmE1NjkzMGIzODlmNWEzY2FmZWY4NDExN2FiZTE2YmJmOWZmNmY=
|
data/bin/mundane
CHANGED
@@ -27,7 +27,14 @@ class MundaneRunner < Thor
|
|
27
27
|
def truncate(desired_length)
|
28
28
|
Mundane.truncate_file_names(desired_length)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
|
+
desc "ban {characters}", "ban/ banfromname strips out the specified characters from file names (don't quote them!)
|
32
|
+
"
|
33
|
+
def ban(banned_characters)
|
34
|
+
Mundane.ban_from_name(banned_characters)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
31
38
|
end
|
32
39
|
|
33
40
|
MundaneRunner.start
|
data/lib/mundane.rb
CHANGED
@@ -6,6 +6,7 @@ require 'mundane/prompter'
|
|
6
6
|
require 'mundane/algos/files_to_zips'
|
7
7
|
require 'mundane/algos/zips_to_files'
|
8
8
|
require 'mundane/algos/truncate_file_names'
|
9
|
+
require 'mundane/algos/ban_from_name'
|
9
10
|
|
10
11
|
|
11
12
|
|
@@ -22,7 +23,11 @@ module Mundane
|
|
22
23
|
def self.truncate_file_names(desired_length)
|
23
24
|
TruncateFileNames.execute(desired_length.to_i)
|
24
25
|
end
|
25
|
-
|
26
|
+
|
27
|
+
def self.ban_from_name(banned_characters)
|
28
|
+
BanFromName.execute(banned_characters)
|
29
|
+
end
|
30
|
+
|
26
31
|
def self.version
|
27
32
|
Mundane::VERSION
|
28
33
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Mundane
|
2
|
+
class BanFromName
|
3
|
+
extend Mundane::FileWorker
|
4
|
+
extend Mundane::Prompter
|
5
|
+
|
6
|
+
def self.execute(banned_characters)
|
7
|
+
user_wants_to_proceed = prompt_user("Are you sure you want to make %count_targeted_files% have offensive characters stripped from their names?\n[Y/n]")
|
8
|
+
|
9
|
+
if user_wants_to_proceed
|
10
|
+
files = get_files_in_current_folder
|
11
|
+
|
12
|
+
ban_from_name(files, banned_characters)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# This algo actually truncates the name and then tacs on the extension at the end
|
19
|
+
def self.ban_from_name(files, banned_characters)
|
20
|
+
require 'fileutils'
|
21
|
+
|
22
|
+
banned_characters = banned_characters.split ""
|
23
|
+
|
24
|
+
files.each do |f|
|
25
|
+
ugly_extension = File.extname(f)
|
26
|
+
pretty_name = f.chomp(File.extname(f))
|
27
|
+
|
28
|
+
resulting_file_name = f.dup
|
29
|
+
banned_characters.each do |char|
|
30
|
+
resulting_file_name.gsub!(char, "")
|
31
|
+
end
|
32
|
+
|
33
|
+
FileUtils.mv f, resulting_file_name if resulting_file_name != f
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
data/lib/mundane/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -21,13 +21,21 @@ def drop_dummy_files_in_working_directory
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def drop_dummy_files_in_working_directory_with_varying_names
|
24
|
-
touch "/tmp/mundane-virtual-working-directory/
|
24
|
+
touch "/tmp/mundane-virtual-working-directory/0houstonfoobar.txt"
|
25
25
|
touch "/tmp/mundane-virtual-working-directory/a"
|
26
26
|
touch "/tmp/mundane-virtual-working-directory/b."
|
27
27
|
touch "/tmp/mundane-virtual-working-directory/c.txt"
|
28
28
|
# touch "/tmp/mundane-virtual-working-directory/c.txtfdsdf"
|
29
29
|
end
|
30
30
|
|
31
|
+
def drop_dummy_files_in_working_directory_with_offending_names
|
32
|
+
touch "/tmp/mundane-virtual-working-directory/0houston,foobar.txt"
|
33
|
+
touch "/tmp/mundane-virtual-working-directory/a$"
|
34
|
+
touch "/tmp/mundane-virtual-working-directory/b."
|
35
|
+
touch "/tmp/mundane-virtual-working-directory/c.txt"
|
36
|
+
# touch "/tmp/mundane-virtual-working-directory/c.txtfdsdf"
|
37
|
+
end
|
38
|
+
|
31
39
|
|
32
40
|
def drop_dummy_zip_file
|
33
41
|
# This string was coppied from a hex editor (bless) on linux
|
data/spec/unit/mundane_spec.rb
CHANGED
@@ -4,6 +4,10 @@ require './lib/mundane'
|
|
4
4
|
require './spec/hack_working_directory' # this require must come LAST or reletive requires will fail hard... oh wait... if there are more test files... everything foobars...
|
5
5
|
|
6
6
|
describe "test the algos" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
extend Mundane::FileWorker
|
10
|
+
end
|
7
11
|
|
8
12
|
describe "test files_to_zips algo" do
|
9
13
|
|
@@ -81,17 +85,47 @@ describe "test the algos" do
|
|
81
85
|
|
82
86
|
Mundane.truncate_file_names(8)
|
83
87
|
|
84
|
-
|
85
88
|
files = get_files_in_current_folder
|
86
89
|
|
87
90
|
files.each do |f|
|
88
91
|
(f.length <= 8).should be_true
|
89
92
|
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "test ban_from_name" do
|
98
|
+
before :each do
|
99
|
+
Mundane::BanFromName.stub(:prompt_user).and_return(true)
|
90
100
|
|
101
|
+
clean_dummy_working_directory
|
102
|
+
end
|
103
|
+
|
104
|
+
after :each do
|
105
|
+
Mundane::BanFromName.unstub(:prompt_user)
|
106
|
+
clean_dummy_working_directory
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should ban chars from name specified" do
|
110
|
+
banned_chars = ",$"
|
91
111
|
|
112
|
+
drop_dummy_files_in_working_directory_with_offending_names
|
113
|
+
|
114
|
+
Mundane.ban_from_name(banned_chars)
|
115
|
+
|
116
|
+
files = get_files_in_current_folder
|
117
|
+
|
118
|
+
files.each do |f|
|
119
|
+
banned_chars.split("").each do |c|
|
120
|
+
f.include?(c).should be_false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
binding.pry
|
92
125
|
end
|
93
126
|
|
94
127
|
end
|
128
|
+
|
95
129
|
|
96
130
|
|
97
131
|
describe "prompter unit test..." do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mundane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- n-jax
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- README
|
108
108
|
- bin/mundane
|
109
109
|
- lib/mundane.rb
|
110
|
+
- lib/mundane/algos/ban_from_name.rb
|
110
111
|
- lib/mundane/algos/files_to_zips.rb
|
111
112
|
- lib/mundane/algos/truncate_file_names.rb
|
112
113
|
- lib/mundane/algos/zips_to_files.rb
|