modname 0.2.2 → 0.2.4

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,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3c0b3f24dde655a0962d82449d6965c5a4dd0818
4
- data.tar.gz: c56ad015da51da9981ac5c13bbbe64009fcdf3a0
2
+ SHA256:
3
+ metadata.gz: ba0fa2d1f63b3777585a4202c0560d15b47c0c345b5c614015baed843d78f099
4
+ data.tar.gz: eb9bbbc814a25107ff88e4dae35ba29a1faebf9701c2af3d70a07a350d2e5eb1
5
5
  SHA512:
6
- metadata.gz: 42221a5eafbf1dff27d3dd42aceead83503a5f66cc4bf120e2b3ec8a4af053df5b96eb024b40742dfdcc1c171e46e2f5de4f51363347ceb296db6209fce7220f
7
- data.tar.gz: 59026395f056e8c74028fa7077b8762321ea8b740f2b8e23447c0fb992dd3cb6656a340a5763e0d90e2a0bed198395ecea1327dfeb7112b00bc9c9b1ab08ebdb
6
+ metadata.gz: 909a24c120475377a6b323d56b4cf0ab1cb1a8b0d6b41a81eb1b241c8a13cbcf76bbbdaf028101456216d674dc2417e61a478113055838a6438cb646927f4ac1
7
+ data.tar.gz: b6686c14fad14cbd7025d39ef985e8ed6dfcb06f0bed43079ca0a01c53724498a4c124a39a592ea0f4906c2ab581779383bf0099c3184142c0d2fb3f4403294e
data/bin/modname CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "modname"
4
+ require 'modname'
4
5
 
5
6
  # modname by jeremy warner
6
7
  # easily rename files/extensions with ruby regex.
7
8
 
8
9
  Modname.run(ARGV)
9
-
@@ -1,39 +1,39 @@
1
- module Modname end
1
+ # frozen_string_literal: true
2
2
 
3
+ # Modname is a versatile file naming tool for renaming groups of files
4
+ module Modname end
3
5
 
4
- Modname::HelpBanner = <<-HELP
5
- #{'Usage:'.cyan} modname [options] <match> [transform]
6
+ Modname::HELP_BANNER = <<~HELP.freeze
7
+ #{'Usage:'.cyan} modname [options] <match> [transform]
6
8
 
7
- #{'modname | rename files, fast'.cyan}
8
- #{'--------┼----------------------------'.cyan}
9
- -e #{'|'.cyan} change file extensions
10
- -f #{'|'.cyan} force run; don't pre-check
11
- -r #{'|'.cyan} run modname recursively
12
- -h #{'|'.cyan} show more help, examples
9
+ #{'modname | rename files, fast'.cyan}
10
+ #{'--------┼----------------------------'.cyan}
11
+ -e #{'|'.cyan} change file extensions
12
+ -f #{'|'.cyan} force run; don't pre-check
13
+ -r #{'|'.cyan} run modname recursively
14
+ -h #{'|'.cyan} show more help, examples
13
15
  HELP
14
16
 
17
+ Modname::V_HELP_BANNER = <<~VHELP.freeze
18
+ #{Modname::HELP_BANNER}
19
+ #{'commands'.cyan}
20
+ file names
21
+ [match] [trans] => modify a pattern in filenames
22
+ [match] => delete a pattern from filenames
15
23
 
16
- Modname::VHelpBanner = <<-VHELP
17
- #{Modname::HelpBanner}
18
- #{'commands'.cyan}
19
- file names
20
- [match] [trans] => modify a pattern in filenames
21
- [match] => delete a pattern from filenames
24
+ extensions (-e)
25
+ [old] [new] => move file extensions, <old> to <new>
26
+ [ext] => lowercase one extension type (EXT => ext)
27
+ nil => move all extensions to lower case
22
28
 
23
- extensions (-e)
24
- [old] [new] => move file extensions, <old> to <new>
25
- [ext] => lowercase one extension type (EXT => ext)
26
- nil => move all extensions to lower case
29
+ #{'examples'.cyan}
30
+ file names
31
+ modname hello => deletes 'hello' from all filenames
32
+ modname hello byebye => replace 'hello' with byebye
27
33
 
28
- #{'examples'.cyan}
29
- file names
30
- modname hello => deletes 'hello' from all filenames
31
- modname hello byebye => replace 'hello' with byebye
34
+ extensions (-e)
35
+ modname -e txt md => move all txt files to markdown
36
+ modname -e mov mp4 => move all mov files to mp4
32
37
 
33
- extensions (-e)
34
- modname -e txt md => move all txt files to markdown
35
- modname -e mov mp4 => move all mov files to mp4
36
-
37
- #{'Note:'.cyan} <required> [optional]
38
+ #{'Note:'.cyan} <required> [optional]
38
39
  VHELP
39
-
@@ -1,15 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # modder, the modname helper
2
4
  # generally: o-old, n-new
3
5
 
4
-
5
6
  # any module including modder should implement:
6
7
  # @transfer => hash of file transfers to occur
7
8
  # @options => hash with :recurse and :force
8
9
 
9
-
10
10
  # extensions
11
11
  module Modder
12
-
13
12
  # rename files based on regular expressions
14
13
  def regex(args = [])
15
14
  match, trans = Modder.parse args
@@ -17,15 +16,14 @@ module Modder
17
16
  Modder.files(@options[:recurse]).each do |file|
18
17
  new = file.sub Regexp.new(match), trans
19
18
 
20
- next if (new == file || new == "") # no changes
19
+ next if new == file || new == '' # no changes
21
20
 
22
21
  @transfer[file] = new
23
22
  end
24
23
 
25
- Modder.finish @transfer, @options[:force]
24
+ Modder.finish @transfer, force: @options[:force]
26
25
  end
27
26
 
28
-
29
27
  # change one file extension to another's type
30
28
  def exts(args = [])
31
29
  match, trans = Modder.parse args
@@ -38,41 +36,39 @@ module Modder
38
36
 
39
37
  else # move match extension to targeted
40
38
  Modder.files(@options[:recurse]).each do |file|
41
- new = file.sub /#{match}$/, trans
39
+ new = file.sub(/#{match}$/, trans)
42
40
 
43
41
  next if new == file # no changes
44
42
 
45
43
  @transfer[file] = new
46
44
  end
47
45
 
48
- Modder.finish @transfer, @options[:force]
46
+ Modder.finish @transfer, force: @options[:force]
49
47
  end
50
48
  end
51
49
 
52
50
  # top level wrapper for exts
53
- def undercase_ext(ext = "")
51
+ def undercase_ext(ext = '')
54
52
  transfer = Modder.undercase_ext_get ext, @options[:recurse]
55
53
  Modder.undercase_ext_set ext, transfer, @options[:force]
56
54
  end
57
55
  end
58
56
 
59
-
60
57
  # module methods
61
58
  class << Modder
62
-
63
59
  # return appropriate args, repairing if undefined
64
60
  def parse(args)
65
61
  match = args.shift
66
62
  trans = args.shift
67
- match = "" if match.nil?
68
- trans = "" if trans.nil?
69
- return match, trans
63
+ match = '' if match.nil?
64
+ trans = '' if trans.nil?
65
+ [match, trans]
70
66
  end
71
67
 
72
68
  # double check transformations
73
69
  def confirm?
74
- print "Are these changes ok? [yN] "
75
- ($stdin.gets.chomp!).downcase[0] == "y"
70
+ print 'Are these changes ok? [yN] '
71
+ $stdin.gets.chomp.downcase[0] == 'y'
76
72
  end
77
73
 
78
74
  # return a list of files to examine
@@ -84,59 +80,56 @@ class << Modder
84
80
  end
85
81
  end
86
82
 
87
-
88
83
  # show the status of current files
89
84
  def status(transfer)
90
85
  if transfer.empty?
91
- puts "No matches found.".yellow
86
+ puts 'No matches found.'.yellow
92
87
  else
93
- puts "Planned file actions:".green
88
+ puts 'Planned file actions:'.green
94
89
  transfer.each { |o, n| puts "\t#{o} -> #{n.green}" }
95
90
  end
96
91
  end
97
92
 
98
93
  # rename all files
99
- def execute(transfer)
100
- transfer.each { |o, n| Modder.rename o, n }
94
+ def execute(transfer, force: false)
95
+ transfer.each { |o, n| Modder.rename o, n, force }
101
96
  end
102
97
 
103
-
104
98
  # finish up execution, highest level wrapper
105
- def finish(transfer, force)
106
-
99
+ def finish(transfer, force: false)
107
100
  # print changes, return if none
108
101
  Modder.status transfer
109
102
  return if transfer.empty?
110
103
 
111
104
  if force || Modder.confirm?
112
- Modder.execute transfer
113
- puts "Modifications complete."
105
+ Modder.execute transfer, force: force
106
+ puts 'Modifications complete.'
114
107
  else
115
- puts "No modifications done."
108
+ puts 'No modifications done.'
116
109
  end
117
110
  end
118
111
 
119
112
  # try to rename a given file
120
- def rename(o, n)
121
- begin
122
- exist = "#{'Error:'.red} target file |#{n.green}| already exists"
123
- (File.exist? n) ? raise(exist) : File.rename(o, n)
124
-
125
- rescue => e
126
- puts "#{'Error:'.red} could not move |#{o.red}| to |#{n.green}|"
127
- puts e.message
128
- end
129
- end
113
+ def rename(old, new, force)
114
+ exist = "#{'Error:'.red} target file |#{new.green}| already exists"
130
115
 
116
+ # only overwrite when forced
117
+ raise(exist) if (!force) && File.exist?(new)
118
+
119
+ File.rename(old, new)
120
+ rescue StandardError => e
121
+ puts "#{'Error:'.red} could not move |#{old.red}| to |#{new.green}|"
122
+ puts e.message
123
+ end
131
124
 
132
125
  # get all extensions to change
133
126
  def undercase_ext_get(ext, recurse)
134
- transfer = Hash.new
127
+ transfer = {}
135
128
  allexts = ext.empty?
136
129
  Modder.files(recurse).each do |file|
137
- ext = file.split(".").last if allexts
130
+ ext = file.split('.').last if allexts
138
131
 
139
- new = file.sub /#{ext}$/i, ext.downcase
132
+ new = file.sub(/#{ext}$/i, ext.downcase)
140
133
  next if new == file || ext == file # no changes or extension
141
134
 
142
135
  transfer[file] = new
@@ -150,7 +143,7 @@ class << Modder
150
143
  # not case sensitive and therefore wont distiniguish between HI and hi.
151
144
  # to get around this, we can set HI to HI.hash, then set HI.hash to hi
152
145
  def undercase_ext_set(ext, transfer, force)
153
- puts "Lowering extension: ".green + (ext.empty?? "*" : ext)
146
+ puts 'Lowering extension: '.green + (ext.empty? ? '*' : ext)
154
147
 
155
148
  Modder.status transfer
156
149
  return if transfer.empty?
@@ -169,10 +162,9 @@ class << Modder
169
162
 
170
163
  Modder.execute temp
171
164
  Modder.execute final
172
- puts "Modifications complete."
165
+ puts 'Modifications complete.'
173
166
  else
174
- puts "No modifications done."
167
+ puts 'No modifications done.'
175
168
  end
176
169
  end
177
170
  end
178
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modname
2
- Version = "0.2.2"
4
+ VERSION = '0.2.4'
3
5
  end
data/lib/modname.rb CHANGED
@@ -1,75 +1,79 @@
1
- # parse modname's command line args
2
-
1
+ # frozen_string_literal: true
3
2
 
4
- require "colored"
5
- require "modname/banner"
6
- require "modname/modder"
7
- require "modname/version"
3
+ # parse modname's command line args
8
4
 
5
+ require 'colored'
6
+ require 'modname/banner'
7
+ require 'modname/modder'
8
+ require 'modname/version'
9
9
 
10
+ # Modname is a versatile file naming tool for renaming groups of files
10
11
  module Modname
11
- class << self # defining Modname.run
12
- def run(x) Driver.new.run x end
12
+ # defining Modname.run
13
+ class << self
14
+ def run(args) = Driver.new.run(args)
13
15
  end
14
16
  end
15
17
 
18
+ # Modname module containing the CLI driver
19
+ module Modname
20
+ # Driver class handles command-line argument parsing and execution
21
+ class Driver
22
+ include Modder
16
23
 
17
- class Modname::Driver
18
- include Modder
19
-
20
- attr_reader :options
24
+ attr_reader :options
21
25
 
22
- def initialize
23
- @options = {:force => false, :recurse => false}
24
- @transfer = {}
25
- end
26
+ def initialize
27
+ @options = { force: false, recurse: false }
28
+ @transfer = {}
29
+ end
26
30
 
27
- # parse user arguments
28
- def run(args)
29
- if args.empty?
30
- puts Modname::HelpBanner
31
- else
32
- opts = parse args
33
- cmd = opts[:cmd]
31
+ # parse user arguments
32
+ def run(args)
33
+ if args.empty?
34
+ puts Modname::HELP_BANNER
35
+ else
36
+ opts = parse args
37
+ cmd = opts[:cmd]
34
38
 
35
- case cmd
36
- when "file"
37
- regex opts[:args]
39
+ case cmd
40
+ when 'file'
41
+ regex opts[:args]
38
42
 
39
- when "ext"
40
- exts opts[:args]
43
+ when 'ext'
44
+ exts opts[:args]
41
45
 
42
- when "help"
43
- puts Modname::VHelpBanner
46
+ when 'help'
47
+ puts Modname::V_HELP_BANNER
44
48
 
45
- when "version"
46
- puts Modname::Version
49
+ when 'version'
50
+ puts Modname::VERSION
51
+ end
47
52
  end
48
53
  end
49
- end
50
-
51
- # parse out arguments
52
- def parse(args)
53
- opts = {:cmd => "file", :args => []}
54
54
 
55
- args.each do |opt|
56
- case opt
57
- when "-f"
58
- @options[:force] = true
59
- when "-r"
60
- @options[:recurse] = true
61
- when "-e", "--ext"
62
- opts[:cmd] = "ext"
63
- when "-h", "--help"
64
- opts[:cmd] = "help"
65
- when "-v", "--version"
66
- opts[:cmd] = "version"
67
- else # command argument
68
- opts[:args] << opt
55
+ # parse out arguments
56
+ def parse(args)
57
+ opts = { cmd: 'file', args: [] }
58
+
59
+ args.each do |opt|
60
+ case opt
61
+ when '-f'
62
+ @options[:force] = true
63
+ when '-r'
64
+ @options[:recurse] = true
65
+ when '-e', '--ext'
66
+ opts[:cmd] = 'ext'
67
+ when '-h', '--help'
68
+ opts[:cmd] = 'help'
69
+ when '-v', '--version'
70
+ opts[:cmd] = 'version'
71
+ else # command argument
72
+ opts[:args] << opt
73
+ end
69
74
  end
70
- end
71
75
 
72
- opts
76
+ opts
77
+ end
73
78
  end
74
79
  end
75
-
data/readme.md CHANGED
@@ -3,7 +3,6 @@ modname
3
3
 
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/modname.svg)](https://badge.fury.io/rb/modname)
6
- [![Build Status](https://travis-ci.org/jeremywrnr/modname.svg?branch=master)](https://travis-ci.org/jeremywrnr/modname)
7
6
  [![MIT](https://img.shields.io/npm/l/alt.svg?style=flat)](http://jeremywrnr.com/mit-license)
8
7
 
9
8
 
@@ -53,6 +52,12 @@ examples
53
52
  Note: <required> [optional]
54
53
  ```
55
54
 
55
+ ### examples
56
+
57
+ modname -e jpeg jpg # change all jpeg file exts to jpg
58
+ modname -e # change all file extensions to lowercase
59
+ modname '(.*)' 'jeremy \1' # use grouping to prepend string
60
+
56
61
 
57
62
  ## development / testing
58
63
 
metadata CHANGED
@@ -1,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modname
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Warner
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-05-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: colored
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: '1.2'
27
26
  - !ruby/object:Gem::Dependency
@@ -39,7 +38,7 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: ronn
41
+ name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
@@ -53,7 +52,7 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: rspec
55
+ name: rspec-mocks
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
@@ -67,19 +66,19 @@ dependencies:
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
69
68
  - !ruby/object:Gem::Dependency
70
- name: rspec-mocks
69
+ name: simplecov
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '0'
74
+ version: 0.22.0
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - ">="
79
+ - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '0'
81
+ version: 0.22.0
83
82
  description: easily rename groups of files with regex replacements.
84
83
  email: jeremywrnr@gmail.com
85
84
  executables:
@@ -97,7 +96,6 @@ homepage: http://github.com/jeremywrnr/modname
97
96
  licenses:
98
97
  - MIT
99
98
  metadata: {}
100
- post_install_message:
101
99
  rdoc_options: []
102
100
  require_paths:
103
101
  - lib
@@ -112,10 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
110
  - !ruby/object:Gem::Version
113
111
  version: '0'
114
112
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.5.1
117
- signing_key:
113
+ rubygems_version: 3.7.2
118
114
  specification_version: 4
119
115
  summary: a versatile file naming tool.
120
116
  test_files: []
121
- has_rdoc: