ebook_renamer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 313909194fe3114ca7d424b52eb470113f9bd89a
4
- data.tar.gz: ed04e84bf1ee591f4230bca25b7b08da6bed5100
3
+ metadata.gz: b0e4104daed6e556eb3241169fba5746f4feabcc
4
+ data.tar.gz: 9fa908281368c84281e7d71e66ba7e7bf8586f73
5
5
  SHA512:
6
- metadata.gz: d33738026713f6e14a0d3616936757fe533cdddd96305ff610905bfd6b62d5e833a7cc85ae1c2a29bfa49a6e310641389db928e76831fe4bd3491d74f166596d
7
- data.tar.gz: a63ccf502342673b44d707b19f0bf95f4e2efe9b3e8dc43a98e1163a1a2f2a694a046282ef97eff641e5ff7daedc542c092481a6903dd4b02e4b7647e2907971
6
+ metadata.gz: a2733518e944cb0a833715fe645556a807b7f36a26340eb1a6f8df0be6d053e0412a81becd752c8dbdba8eb4c0049f06bbc6272545726f0bbb21ccbcfb5faff2
7
+ data.tar.gz: 7c5694af153aead28f0a82857a4fda073d2b6a4f87a8a18b2328aff47830a0175f81199c826399a80949e6b7641c2a187d53d8623c940979c0b8b59f84e3c11b
data/Guardfile CHANGED
@@ -1,6 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
  guard 'minitest' do
4
+
4
5
  # with Minitest::Unit
5
6
  watch(%r|^test/(.*)\/?test_(.*)\.rb|)
6
7
  watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
@@ -11,13 +12,4 @@ guard 'minitest' do
11
12
  # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
13
  # watch(%r|^spec/spec_helper\.rb|) { "spec" }
13
14
 
14
- # Rails 3.2
15
- # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
16
- # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
17
- # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
18
-
19
- # Rails
20
- # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
21
- # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
22
- # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
23
15
  end
data/README.md CHANGED
@@ -142,14 +142,17 @@ the output will be something like `Start.with.Why.How.Great.Leader.Inspire.Every
142
142
  --commit
143
143
 
144
144
  6) $ebook_renamer --base-dir ~/Dropbox/ebooks
145
- --meta-binary ebook-meta
146
145
  --recursive
147
146
  --commit
148
147
 
148
+ 7) $ebook_renamer --base-dir ~/Dropbox/ebooks
149
+ --recursive
150
+ --sep-string '_'
151
+ --commit
149
152
  Options:
150
153
 
151
154
  -b, --base-dir directory Starting directory [default - current directory]
152
- -m, --meta-binary path The ebook-meta executable [default - 'ebook-meta']
155
+ -s, --sep-string string Separator string [default - '.']
153
156
  -r, --recursive Process the files recursively [default - false]
154
157
  -c, --commit Perform the actual rename [default - false]
155
158
  -v, --version Display version number
@@ -158,6 +161,10 @@ the output will be something like `Start.with.Why.How.Great.Leader.Inspire.Every
158
161
 
159
162
  ### Changelog
160
163
 
164
+ #### 0.0.7
165
+
166
+ - More improvement and code cleanup
167
+
161
168
  #### 0.0.6
162
169
 
163
170
  - Fix and update README.md
data/bin/ebook_renamer CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  begin
3
- require 'pry'
4
3
  require 'ebook_renamer'
5
4
  rescue LoadError
6
5
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
@@ -13,12 +12,14 @@ require 'ostruct'
13
12
 
14
13
  begin
15
14
  options = parse_options()
16
- EbookRenamer.logger.info "Your options: #{options}"
17
- meta_binary = options.delete(:meta_binary)
15
+ EbookRenamer.logger.debug "Your options: #{options}"
16
+
17
+ #meta_binary = options.delete(:meta_binary)
18
+ sep_string = options.delete(:sep_string)
18
19
 
19
- # Note: if we need to adjust the path to the executable
20
20
  EbookRenamer.configure do |config|
21
- config.meta_binary = meta_binary if meta_binary
21
+ #config.meta_binary = meta_binary if meta_binary
22
+ config.sep_string = sep_string if sep_string
22
23
  end
23
24
 
24
25
  cli = EbookRenamer::CLI.new(EbookRenamer.configuration)
@@ -16,10 +16,10 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
- # Generated dependencies
19
+
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake"
22
- # additional dependencies
22
+
23
23
  spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
24
24
  spec.add_development_dependency "guard-minitest", "~> 2.2"
25
25
  spec.add_development_dependency "minitest", "~> 4.2"
data/lib/ebook_renamer.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'ebook_renamer/version'
2
2
  require 'ebook_renamer/logger'
3
- require 'ebook_renamer/constant'
4
3
  require 'ebook_renamer/helpers'
5
4
  require 'ebook_renamer/configuration'
6
5
  require 'ebook_renamer/options'
@@ -15,6 +15,7 @@ module EbookRenamer
15
15
  # :recursive - perform the rename recursively (true|false)
16
16
  # :commit - make the rename permanent (true|false)
17
17
  # :exts - list of extensions to be processed default to ['epub,mobi,pdf']
18
+ #
18
19
  # @param base_dir [String] base directory default to current directory
19
20
  # @param args [Hash<Symbol, Object>] options argument
20
21
  def rename(base_dir = Dir.pwd, args = {})
@@ -26,23 +27,28 @@ module EbookRenamer
26
27
 
27
28
  input_files = Helpers.files(base_dir, options).sort
28
29
 
30
+ unless options[:commit]
31
+ puts "Changes will not be applied without the --commit option."
32
+ end
33
+
29
34
  input_files.each do |file|
30
- puts "Input :#{file}"
31
35
  extension = File.extname(file)
32
36
  begin
33
37
  hash = Helpers.meta_to_hash(Helpers.meta(file, config.meta_binary))
34
38
  formatted_name = Helpers.formatted_name(hash, sep_char: " by ")
35
39
  formatted_name = "#{formatted_name}#{extension}"
36
- new_name = "#{File.dirname(file)}/#{Helpers.sanitize_filename(formatted_name, '.')}"
37
- puts "Output:#{new_name}"
40
+ new_name = "#{File.dirname(file)}/#{Helpers.sanitize_filename(formatted_name, config.sep_string)}"
41
+ puts "[#{file}] -> [#{new_name}]"
42
+
43
+ # TODO: handle this properly!
38
44
  # skip if the filename is too long '228'
39
45
  # see: https://github.com/rails/rails/commit/ad95a61b62e70b839567c2e91e127fc2a1acb113
40
- # @todo find out the max file size
41
46
  max_allowed_file_size = 220
42
47
  if new_name && new_name.size > max_allowed_file_size
43
48
  puts "FYI: skip file name too long [#{new_name.size}] : #{new_name}"
44
49
  next
45
50
  end
51
+
46
52
  FileUtils.mv(file,new_name) if options[:commit] && file != new_name && new_name.size < max_allowed_file_size
47
53
  rescue RuntimeError => e
48
54
  puts e.backtrace
@@ -1,16 +1,14 @@
1
1
  module EbookRenamer
2
2
  class Configuration
3
-
3
+ # the separator char for each word in the file name
4
4
  attr_accessor :meta_binary
5
5
 
6
- def initialize
7
- @meta_binary = '/usr/bin/ebook-meta'
8
- end
6
+ # the separator char for each word in the file name
7
+ attr_accessor :sep_string
9
8
 
10
- def to_s
11
- <<-END.gsub(/^\s+\|/, '')
12
- | ebook-meta : #{meta_binary}
13
- END
9
+ def initialize
10
+ @meta_binary = 'ebook-meta'
11
+ @sep_string = '.'
14
12
  end
15
13
  end
16
14
 
@@ -27,7 +27,6 @@ module EbookRenamer::Options
27
27
  | --commit
28
28
  |
29
29
  | 6) $ebook_renamer --base-dir ~/Dropbox/ebooks
30
- | --meta-binary ebook-meta
31
30
  | --recursive
32
31
  | --commit
33
32
  |
@@ -40,9 +39,9 @@ module EbookRenamer::Options
40
39
  options[:base_dir] = base_dir
41
40
  end
42
41
 
43
- options[:meta_binary] ||= 'ebook-meta'
44
- opts.on('-m', '--meta-binary path', "The ebook-meta executable [default - 'ebook-meta']") do |binary|
45
- options[:meta_binary] = binary
42
+ options[:sep_string] ||= '.'
43
+ opts.on('-s', '--sep-string string', "Separator string [default - '.']") do |sep_string|
44
+ options[:sep_string] = sep_string
46
45
  end
47
46
 
48
47
  options[:recursive] = false
@@ -1,3 +1,3 @@
1
1
  module EbookRenamer
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -3,7 +3,7 @@ describe EbookRenamer do
3
3
 
4
4
  before :each do
5
5
  EbookRenamer.configure do |config|
6
- config.meta_binary = '/usr/bin/ebook-meta'
6
+ config.meta_binary = 'ebook-meta'
7
7
  end
8
8
  end
9
9
 
@@ -12,11 +12,11 @@ describe EbookRenamer do
12
12
  end
13
13
 
14
14
  it "uses the updated configuration" do
15
- EbookRenamer.configuration.meta_binary.must_equal '/usr/bin/ebook-meta'
15
+ EbookRenamer.configuration.meta_binary.must_equal 'ebook-meta'
16
16
  config = EbookRenamer.configure do |config|
17
- config.meta_binary = "ebook-meta"
17
+ config.meta_binary = "new-ebook-meta"
18
18
  end
19
- EbookRenamer.configuration.meta_binary.must_equal 'ebook-meta'
19
+ EbookRenamer.configuration.meta_binary.must_equal 'new-ebook-meta'
20
20
  end
21
21
 
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebook_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -172,7 +172,6 @@ files:
172
172
  - lib/ebook_renamer.rb
173
173
  - lib/ebook_renamer/cli.rb
174
174
  - lib/ebook_renamer/configuration.rb
175
- - lib/ebook_renamer/constant.rb
176
175
  - lib/ebook_renamer/helpers.rb
177
176
  - lib/ebook_renamer/logger.rb
178
177
  - lib/ebook_renamer/options.rb
@@ -1,13 +0,0 @@
1
- module EbookRenamer
2
- # The Calibre metadata extraction tool (epub, mobi, pdf)
3
- CALIBRE_CLI_BINARY = '/usr/bin/ebook-meta'
4
-
5
- # The Calibre metadata extraction tool
6
- CALIBRE_META_CLI = '/usr/bin/ebook-meta'
7
-
8
- # Support URL for Calibre's CLI tool
9
- CALIBRE_CLI_URL = 'http://manual.calibre-ebook.com/cli/cli-index.html'
10
-
11
- # Attribute keys
12
- META_KEYS = %w[title authors(s) publisher languages published rights identifiers]
13
- end