umruhren 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: 3725a72cdeda4c7a1165231d21d1fbe6d5309687
4
+ data.tar.gz: a404bc17e8c963dae2f37eee8e47dc457a04f7c1
5
+ SHA512:
6
+ metadata.gz: 92814f4fde045ba7c1a46c7fa20339af420ad129c1ed7d516ab6dcd7d88f95fdffe7e386b3ff8cdbd6c6a9236206da69447d65b8f8d179ab314e4e67238e5e74
7
+ data.tar.gz: b400e927d58305ab19122b0b5fa81c0e705b8d7afad2dca361a61b344a96dbc9a419551829fcea92650e475686aad6b7392ead4f896d7630050dbbf8855953d0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in umruhren.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Umruhren
2
+
3
+ Command line application.
4
+ Renames files in specified dir with selected extension with random names.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'umruhren'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install umruhren
19
+
20
+ ## Usage
21
+
22
+ dir is optional option, default is current directory.
23
+
24
+ ```
25
+ umruhren --ext mp3 --dir /Volumes/Untitled
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/umruhren ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'yaml'
5
+
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
7
+ require 'umruhren'
8
+
9
+ options = {
10
+ dir: Dir.pwd
11
+ }
12
+
13
+ CONFIG_FILE = File.join(ENV['HOME'], '.umruhren.rc.yaml')
14
+
15
+ if File.exists? CONFIG_FILE
16
+ config_options = YAML.load_file(CONFIG_FILE)
17
+ options.merge!(config_options)
18
+ else
19
+ begin
20
+ File.open(CONFIG_FILE, 'w') { |file| YAML::dump(options, file) }
21
+ STDERR.puts "Initialized configuration file in #{CONFIG_FILE}"
22
+ rescue Errno::EACCES => ex
23
+ #STDERR.puts "Cannot create config file. #{ex.message}"
24
+ end
25
+ end
26
+
27
+ option_parser = OptionParser.new do |opts|
28
+ executable_name = File.basename($PROGRAM_NAME)
29
+ opts.banner = <<EOF
30
+ Creates random names for files with chosen extension in dir.
31
+
32
+ Usage: #{executable_name} [options]
33
+
34
+ EOF
35
+
36
+ opts.on("-e EXTENSION", "--ext", "Files extension") do |ext|
37
+ options[:ext] = ext
38
+ end
39
+
40
+ opts.on("-d DIRECTORY", "--dir", "Directory") do |dir|
41
+ options[:dir] = dir
42
+ end
43
+ end
44
+
45
+ begin
46
+ option_parser.parse!
47
+ if options[:ext].nil?
48
+ puts "Missing option --ext"
49
+ exit 1
50
+ end
51
+ rescue OptionParser::InvalidArgument => ex
52
+ STDERR.puts ex.message
53
+ STDERR.puts option_parser
54
+ exit 1
55
+ end
56
+
57
+ files = Umruhren.rename_files(options[:dir], options[:ext])
58
+ puts "Renamed #{files.size} files."
@@ -0,0 +1,3 @@
1
+ module Umruhren
2
+ VERSION = "0.0.1"
3
+ end
data/lib/umruhren.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'umruhren/version'
2
+ require 'set'
3
+
4
+ module Umruhren
5
+ CHARS = %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f )
6
+
7
+ class << self
8
+ def rename_files(dir, ext)
9
+ files = Dir[dir + "/*.#{ext}"]
10
+ new_names = rand_string_array(files.size)
11
+ files.each_with_index do |f, i|
12
+ File.rename(f, dir + "/" + new_names[i] + File.extname(f))
13
+ end
14
+ end
15
+
16
+ private
17
+ def rand_string(length = 12)
18
+ (1..length).map{ CHARS.sample }.join
19
+ end
20
+
21
+ def rand_string_array(size)
22
+ randoms = Set.new
23
+ loop do
24
+ randoms << rand_string
25
+ return randoms.to_a if randoms.size >= size
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path("../lib/promo")
2
+ require 'umruhren'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Umruhren do
4
+ it 'creates rand_string of specified length' do
5
+ subject::CHARS.should_receive(:sample).exactly(4).times.and_return('H')
6
+ subject.send(:rand_string, 4).should == 'HHHH'
7
+ end
8
+
9
+ it 'creates rand_string_array of specified size' do
10
+ subject.should_receive(:rand_string).and_return '1234'
11
+ subject.should_receive(:rand_string).and_return 'abcd'
12
+ subject.send(:rand_string_array, 2).should == ['1234', 'abcd']
13
+ end
14
+
15
+ it 'renames files in specified dir with selected extension' do
16
+ Dir.should_receive(:[]).with('/path/to/dir/*.ext').and_return %w(/path/to/dir/one.ext /path/to/dir/two.ext /path/to/dir/three.ext)
17
+ subject.should_receive(:rand_string_array).with(3).and_return %w(f1 f2 f3)
18
+ File.should_receive(:rename).with('/path/to/dir/one.ext', '/path/to/dir/f1.ext')
19
+ File.should_receive(:rename).with('/path/to/dir/two.ext', '/path/to/dir/f2.ext')
20
+ File.should_receive(:rename).with('/path/to/dir/three.ext', '/path/to/dir/f3.ext')
21
+ subject.rename_files('/path/to/dir', 'ext')
22
+ end
23
+ end
data/umruhren.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'umruhren/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "umruhren"
8
+ spec.version = Umruhren::VERSION
9
+ spec.authors = ["Alexander Avoyants"]
10
+ spec.email = ["shhavel@gmail.com"]
11
+ spec.description = %q{Renames files in specified dir with selected extension with random namesn}
12
+ spec.summary = %q{Command line application. Renames files in specified dir with selected extension with random names}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: umruhren
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Avoyants
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-16 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Renames files in specified dir with selected extension with random namesn
56
+ email:
57
+ - shhavel@gmail.com
58
+ executables:
59
+ - umruhren
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .rspec
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/umruhren
68
+ - lib/umruhren.rb
69
+ - lib/umruhren/version.rb
70
+ - spec/spec_helper.rb
71
+ - spec/umruhren_spec.rb
72
+ - umruhren.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Command line application. Renames files in specified dir with selected extension
97
+ with random names
98
+ test_files:
99
+ - spec/spec_helper.rb
100
+ - spec/umruhren_spec.rb