web_safe_filename 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6223884d12a8d765badcbf08f9504eb46814080e
4
+ data.tar.gz: c605793ec12995b98d22d167a8a5280a79c4000a
5
+ SHA512:
6
+ metadata.gz: 46be502684ebc91a7bb5b1c598a007261af248c042c59bea1527887e0051f744ba691ff736c4ddadc1254caf1be2a2575697e7fd4a36a8becae4f86a8936e43f
7
+ data.tar.gz: 2abb6c65dcca37d0b6ab0c258b8b17f3257b33e60dee8ad50b8947b0596ffe348afd8e8a04e3db721306cc32da6a11a7bb23adfb311c5a88ec614da56a9b21e3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in web_safe_filename.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dave Shaffer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Web-Safe Filename
2
+
3
+ This is a command line Ruby script for batch converting filenames. This script recursively parses the current directory and child directories and converts all web-safe characters into dashes.
4
+
5
+ by [Dave Shaffer](mailto:dave.shaffer@gmail.com)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'web_safe_filename'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install web_safe_filename
22
+
23
+ ## Usage
24
+
25
+ Run `web_safe_filename` from the terminal in the desired directory. It is unlikely you will want use this in a Rails application, but be sure to run it in the right directory if you do, since this script will touch everything.
26
+
27
+ ## Tests
28
+
29
+ To run the tests, clone the repository and run `rake` or `rake test` in the repo directory. This will create a bunch of test files in `spec/test_files` and then delete them upon completion. Any feedback on how to improve the test coverage would be awesome since there's really only one test.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/web_safe_filename/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'spec'
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc 'Run tests'
11
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'web_safe_filename'
4
+
5
+ include WebSafeFilename
6
+
7
+ WebSafeFilename::Scrubber.start
@@ -0,0 +1,3 @@
1
+ module WebSafeFilename
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'web_safe_filename/version'
2
+ require 'uri'
3
+
4
+ module WebSafeFilename
5
+ class Scrubber
6
+
7
+ def self.start
8
+ new.traverse_directories
9
+ end
10
+
11
+ def scrub(file)
12
+ File.rename(file, file.gsub(/[\x00\\:\*\?\"<>\|,#\$\@\%\!\^\~ ]/, '-'))
13
+ end
14
+
15
+ def traverse_directories(directory = Dir.pwd)
16
+ Dir.chdir(directory) do
17
+ Dir.glob('*').each do |entry|
18
+ traverse_directories(entry) if File.directory?(entry)
19
+ scrub(entry)
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'fileutils'
4
+ require 'web_safe_filename'
5
+
6
+ # Test helpers
7
+
8
+ def generate_random_filename(length, start_char = 32)
9
+ Array.new(length) { rand(start_char..126) }
10
+ .reject {|i| [42,47,92].include?(i) }
11
+ .map { |c| c.chr }.join
12
+ end
13
+
14
+ def generate_name_list
15
+ list = []
16
+ rand(1..30).times { list << generate_random_filename(30) }
17
+ list
18
+ end
19
+
20
+ def generate_test_files
21
+ Dir.mkdir('spec/test_files') unless Dir.exist?('spec/test_files')
22
+ Dir.chdir('spec/test_files') do
23
+ dirs = generate_name_list
24
+ FileUtils.mkdir(dirs)
25
+ dirs.each do |dir|
26
+ Dir.chdir(dir) { FileUtils.touch(generate_name_list) }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe WebSafeFilename do
4
+ before do
5
+ generate_test_files
6
+ end
7
+
8
+ after do
9
+ FileUtils.rm_rf('spec/test_files')
10
+ end
11
+
12
+ it 'should rename files and folders' do
13
+ Dir.chdir('spec/test_files') do
14
+ before_dir_list = Dir.glob('*')
15
+ WebSafeFilename::Scrubber.start
16
+ before_dir_list.wont_equal Dir.glob('*')
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'web_safe_filename/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "web_safe_filename"
8
+ spec.version = WebSafeFilename::VERSION
9
+ spec.authors = ["Dave Shaffer"]
10
+ spec.email = ["dave.shaffer@gmail.com"]
11
+ spec.summary = %q{CLI script for batch renaming files.}
12
+ spec.description = %q{This script will recursively rename all files in all directories under where it is run. This is pretty dangerous crap so I don't recommend doing it.}
13
+ spec.homepage = "http://daveshaffer.co"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_safe_filename
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Shaffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This script will recursively rename all files in all directories under
42
+ where it is run. This is pretty dangerous crap so I don't recommend doing it.
43
+ email:
44
+ - dave.shaffer@gmail.com
45
+ executables:
46
+ - web_safe_filename
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/web_safe_filename
56
+ - lib/web_safe_filename.rb
57
+ - lib/web_safe_filename/version.rb
58
+ - spec/spec_helper.rb
59
+ - spec/web_safe_filename_spec.rb
60
+ - web_safe_filename.gemspec
61
+ homepage: http://daveshaffer.co
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: CLI script for batch renaming files.
85
+ test_files:
86
+ - spec/spec_helper.rb
87
+ - spec/web_safe_filename_spec.rb