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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjE5MmViNjA5MmE0MDU4ZWZlOWE1OWJiZWZhZjQ1MmE1MDU3NWZmYg==
4
+ MThiY2U3ZDljZTAwNmJkOTRjMzc2N2JkNzQ5MGRiN2FkMGE1ZDZlYQ==
5
5
  data.tar.gz: !binary |-
6
- OTg5NWMxOTI3YmQyZWEzYzJhODBmM2NjYTA2MDU4ZGU1NGViOWI1Yw==
6
+ ZTkzNTY4YTQ3MDhlOGI0N2FjMGFhNGJkZjE1M2Q1ZTJkZTA3M2NmYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjM1YWI1YzdlOGZjNTE2YWE1MjgwZjM3ZjZmNTViMzU5M2Q4MjY2MzA4NmMz
10
- ODI4OWI0ZDk0ZDgyNTFiYTdiNDBjMTZkYTk0OTJjZDA3NTVlNTgwMzFiMzE3
11
- NzU3NjM1ZGRkYmU0Mjg1NjIxZDNjNmU1NDE5YWJkYjM2ZWE2NGU=
9
+ ZTNmM2UxNjUzMjQ5ZTRjNDViZjBhMzM0YjMyMGI0ZGFhYjQ0NWJlZTVjMzRh
10
+ NmMwMGRhZjQzNmNkMTY3NGE3ZjA5ZmQ0NzZkZTcwZmMxMDMwYzllZjdhYWJm
11
+ ZDViYzBkMzM2N2UxZTYyYWRkNTRhZTcxMjc1YzE2NWUyZTkwMGI=
12
12
  data.tar.gz: !binary |-
13
- OGRlYzAxMjhhNjA5MDRkODg5YjljZWEzNjJiYjZmYzZjNmQ1OWM0ODE1ODI3
14
- OTcxYmY3NDA4M2MyYTdjZjhjZmRkNmY5YjQ0MjIxMTg1NGEzZDBiOWFhNDNl
15
- M2JhMjJmZmEyY2E0ZDM5NzgzZDU5ZWMxZTljZDk5YzVkZTQ2MDU=
13
+ MmE2ZTRiNzM5M2RiZDk4MmQxZDYzMmM1NDNkNzcwNTk2NzU0Y2JlNjNiNTIw
14
+ MjEzYWRhMTAxNjUxYjkxZjQxMjVhNzcyZDg4MTY3YWI5ZWRhNjg3MmE3ZjVh
15
+ NmE1NjkzMGIzODlmNWEzY2FmZWY4NDExN2FiZTE2YmJmOWZmNmY=
@@ -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
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module Mundane
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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/houstonfoobar.txt"
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
@@ -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
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