ebooks_renamer 0.1.3 → 0.1.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 +4 -4
- data/.rubocop.yml +94 -2
- data/Gemfile +1 -1
- data/README.md +3 -3
- data/Rakefile +10 -10
- data/bin/ebooks_renamer +6 -2
- data/ebooks_renamer.gemspec +1 -2
- data/lib/ebooks_renamer.rb +6 -6
- data/lib/ebooks_renamer/cli.rb +12 -15
- data/lib/ebooks_renamer/core_ext/hash/keys.rb +0 -1
- data/lib/ebooks_renamer/ebooks_renamer.rb +19 -19
- data/lib/ebooks_renamer/logger.rb +1 -1
- data/lib/ebooks_renamer/pdf_parser.rb +3 -3
- data/lib/ebooks_renamer/version.rb +1 -1
- metadata +2 -3
- data/rubocop-todo.yml +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcfe69c874481fe5d47d0b09b97899fb97bbe3a0
|
4
|
+
data.tar.gz: 104930f2174f8ae0c68be45e6afcb6cd57a182b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b762829046bc8baca50428bb463a0e64c517f1ce33bfb006869a9516a27e3d6996724925fda2416a5e0bf8e655f0d8bf644d84274d01ad045bef15095eadac1
|
7
|
+
data.tar.gz: 3764692ae672455ff62d75cfab9f1404e8dab0a75d1f41665660be6a9acc7ec80cdadc07c42f56d5c4161214f1314cbec690075a26811fd0b4aaffa05fb058c5
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,95 @@
|
|
1
|
-
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Gemfile
|
4
|
+
- Rakefile
|
5
|
+
- bin/*
|
6
|
+
- ebooks_cleaner.gemspec
|
7
|
+
- lib/**/*.rb
|
8
|
+
- test/**/*.rb
|
9
|
+
# Avoid long parameter lists
|
10
|
+
ParameterLists:
|
11
|
+
Max: 5
|
12
|
+
CountKeywordArgs: true
|
2
13
|
|
3
|
-
|
14
|
+
MethodLength:
|
15
|
+
CountComments: false
|
16
|
+
Max: 15
|
17
|
+
|
18
|
+
# Avoid more than `Max` levels of nesting.
|
19
|
+
BlockNesting:
|
20
|
+
Max: 4
|
21
|
+
|
22
|
+
# Align with the style guide.
|
23
|
+
CollectionMethods:
|
24
|
+
PreferredMethods:
|
25
|
+
collect: 'map'
|
26
|
+
inject: 'reduce'
|
27
|
+
find: 'detect'
|
28
|
+
find_all: 'select'
|
29
|
+
|
30
|
+
# Do not force public/protected/private keyword to be indented at the same
|
31
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
32
|
+
# because I think when scanning code it makes it easier to identify the
|
33
|
+
# sections of code and visually separate them. When the keyword is at the same
|
34
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
35
|
+
# to scan the code and see where the sections are.
|
36
|
+
AccessModifierIndentation:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Limit line length
|
40
|
+
LineLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Disable documentation checking until a class needs to be documented once
|
44
|
+
Documentation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Enforce Ruby 1.8-compatible hash syntax
|
48
|
+
HashSyntax:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# No spaces inside hash literals
|
52
|
+
SpaceInsideHashLiteralBraces:
|
53
|
+
EnforcedStyle: no_space
|
54
|
+
|
55
|
+
# Allow dots at the end of lines
|
56
|
+
DotPosition:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Don't require magic comment at the top of every file
|
60
|
+
Encoding:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# Enforce outdenting of access modifiers (i.e. public, private, protected)
|
64
|
+
AccessModifierIndentation:
|
65
|
+
EnforcedStyle: outdent
|
66
|
+
|
67
|
+
EmptyLinesAroundAccessModifier:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
# Align ends correctly
|
71
|
+
EndAlignment:
|
72
|
+
AlignWith: variable
|
73
|
+
|
74
|
+
# Indentation of when/else
|
75
|
+
CaseIndentation:
|
76
|
+
IndentWhenRelativeTo: end
|
77
|
+
IndentOneStep: false
|
78
|
+
|
79
|
+
DoubleNegation:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
PercentLiteralDelimiters:
|
83
|
+
PreferredDelimiters:
|
84
|
+
'%': ()
|
85
|
+
'%i': ()
|
86
|
+
'%q': ()
|
87
|
+
'%Q': ()
|
88
|
+
'%r': '{}'
|
89
|
+
'%s': ()
|
90
|
+
'%w': '[]'
|
91
|
+
'%W': '[]'
|
92
|
+
'%x': ()
|
93
|
+
|
94
|
+
StringLiterals:
|
95
|
+
EnforcedStyle: double_quotes
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -60,7 +60,7 @@ Or install it yourself as:
|
|
60
60
|
|
61
61
|
```
|
62
62
|
Usage:
|
63
|
-
ebooks_renamer
|
63
|
+
ebooks_renamer
|
64
64
|
|
65
65
|
Options:
|
66
66
|
-b, [--base-dir=BASE_DIR] # Base directory
|
@@ -90,11 +90,11 @@ rbenv local 2.1.2 # or any version after 1.9+
|
|
90
90
|
gem install ebooks_renamer
|
91
91
|
|
92
92
|
# run the command without making any changes
|
93
|
-
ebooks_renamer
|
93
|
+
ebooks_renamer --base-dir . --recursive
|
94
94
|
|
95
95
|
# If you are happy with what will be changed then you can make your change permanent
|
96
96
|
|
97
|
-
ebooks_renamer
|
97
|
+
ebooks_renamer --base-dir . --recursive --commit
|
98
98
|
|
99
99
|
# To change the default separator string `sep_string` (default to '.' - dot string)
|
100
100
|
# e.g. this will use the '_' (underscore) to separate each word in the output
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
project_name =
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
project_name = "ebooks_renamer"
|
4
4
|
|
5
5
|
Rake::TestTask.new do |t|
|
6
6
|
t.libs << "lib/#{project_name}"
|
@@ -10,20 +10,20 @@ end
|
|
10
10
|
|
11
11
|
task default: [:test, :rubocop]
|
12
12
|
task :pry do
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require_relative
|
13
|
+
require "pry"
|
14
|
+
require "awesome_print"
|
15
|
+
require_relative "lib/ebook_meta"
|
16
16
|
include EbooksRenamer
|
17
17
|
ARGV.clear
|
18
18
|
Pry.start
|
19
19
|
end
|
20
20
|
|
21
|
-
require
|
22
|
-
desc
|
21
|
+
require "rubocop/rake_task"
|
22
|
+
desc "Run RuboCop on the lib directory"
|
23
23
|
Rubocop::RakeTask.new(:rubocop) do |task|
|
24
|
-
task.patterns = [
|
24
|
+
task.patterns = ["lib/**/*.rb"]
|
25
25
|
# only show the files with failures
|
26
|
-
task.formatters = [
|
26
|
+
task.formatters = ["files"]
|
27
27
|
# don't abort rake on failure
|
28
28
|
task.fail_on_error = false
|
29
29
|
end
|
data/bin/ebooks_renamer
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require_relative
|
2
|
+
require_relative "../lib/ebooks_renamer"
|
3
3
|
include EbooksRenamer
|
4
|
-
|
4
|
+
if ARGV.empty?
|
5
|
+
EbooksRenamer::CLI.start(%w[usage])
|
6
|
+
else
|
7
|
+
EbooksRenamer::CLI.start(%w[rename].concat(ARGV))
|
8
|
+
end
|
data/ebooks_renamer.gemspec
CHANGED
@@ -17,8 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
README.md
|
18
18
|
LICENSE
|
19
19
|
.rubocop.yml
|
20
|
-
.gitignore
|
21
|
-
rubocop-todo.yml)
|
20
|
+
.gitignore)
|
22
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
23
|
spec.require_paths = ['lib']
|
data/lib/ebooks_renamer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
1
|
+
require_relative "ebooks_renamer/version"
|
2
|
+
require_relative "ebooks_renamer/logger"
|
3
|
+
require_relative "ebooks_renamer/cli"
|
4
|
+
require_relative "ebooks_renamer/core_ext/hash/keys"
|
5
|
+
require_relative "ebooks_renamer/core_ext/object/blank"
|
6
|
+
require_relative "ebooks_renamer/ebooks_renamer"
|
7
7
|
include EbooksRenamer
|
data/lib/ebooks_renamer/cli.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require_relative
|
1
|
+
require "thor"
|
2
|
+
require "agile_utils"
|
3
|
+
require_relative "ebooks_renamer"
|
4
4
|
module EbooksRenamer
|
5
5
|
class CLI < Thor
|
6
|
-
desc
|
6
|
+
desc "rename", "Rename ebooks based on given criteria"
|
7
7
|
method_option *AgileUtils::Options::BASE_DIR
|
8
8
|
method_option *AgileUtils::Options::RECURSIVE
|
9
9
|
method_option *AgileUtils::Options::VERSION
|
10
|
-
|
11
10
|
method_option :sep_string,
|
12
|
-
aliases:
|
13
|
-
desc:
|
14
|
-
default:
|
15
|
-
|
11
|
+
aliases: "-s",
|
12
|
+
desc: "Separator string between words in filename",
|
13
|
+
default: "."
|
16
14
|
method_option :commit,
|
17
|
-
aliases:
|
18
|
-
desc:
|
15
|
+
aliases: "-c",
|
16
|
+
desc: "Make change permanent",
|
19
17
|
type: :boolean,
|
20
18
|
default: false
|
21
|
-
|
22
19
|
def rename
|
23
20
|
opts = options.symbolize_keys
|
24
21
|
if opts[:version]
|
@@ -26,17 +23,17 @@ module EbooksRenamer
|
|
26
23
|
exit
|
27
24
|
end
|
28
25
|
# Add the default supported extensions
|
29
|
-
opts.merge!(exts: %w
|
26
|
+
opts.merge!(exts: %w[pdf epub mobi])
|
30
27
|
puts "Your options #{opts}"
|
31
28
|
EbooksRenamer.rename(opts)
|
32
29
|
end
|
33
30
|
|
34
|
-
desc
|
31
|
+
desc "usage", "Display help screen"
|
35
32
|
def usage
|
36
33
|
puts <<-EOS
|
37
34
|
|
38
35
|
Usage:
|
39
|
-
ebooks_renamer
|
36
|
+
ebooks_renamer
|
40
37
|
|
41
38
|
Options:
|
42
39
|
-b, [--base-dir=BASE_DIR] # Base directory
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
1
|
+
require "mobi"
|
2
|
+
require "epubinfo"
|
3
|
+
require "pdf-reader"
|
4
|
+
require "ostruct"
|
5
|
+
require "fileutils"
|
6
|
+
require "filename_cleaner"
|
7
|
+
require "code_lister"
|
8
|
+
require_relative "pdf_parser"
|
9
|
+
require_relative "epub_parser"
|
10
|
+
require_relative "mobi_parser"
|
11
11
|
module EbooksRenamer
|
12
12
|
CustomError = Class.new(StandardError)
|
13
13
|
class << self
|
@@ -25,20 +25,20 @@ module EbooksRenamer
|
|
25
25
|
else
|
26
26
|
puts "#{index + 1} of #{files.length}: Result : '#{old_name}' is identical so no action taken."
|
27
27
|
end
|
28
|
-
rescue
|
28
|
+
rescue => e
|
29
29
|
puts "Skip file '#{file}'"
|
30
30
|
puts "Due to the unexpected error: #{e.message}"
|
31
31
|
next
|
32
32
|
end
|
33
33
|
end
|
34
34
|
unless options[:commit]
|
35
|
-
puts
|
36
|
-
puts
|
37
|
-
puts
|
35
|
+
puts "------------------------------------------------------------------"
|
36
|
+
puts "This is a dry run only, to actually rename please specify --commit"
|
37
|
+
puts "------------------------------------------------------------------"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
private
|
42
42
|
|
43
43
|
def formatted_name(file, sep_string)
|
44
44
|
meta = parse(file)
|
@@ -53,7 +53,7 @@ module EbooksRenamer
|
|
53
53
|
File::SEPARATOR,
|
54
54
|
FilenameCleaner.sanitize(name, sep_string, false),
|
55
55
|
File.extname(file),
|
56
|
-
].join(
|
56
|
+
].join("")
|
57
57
|
else
|
58
58
|
# return the full path of the original file
|
59
59
|
File.expand_path(file)
|
@@ -73,11 +73,11 @@ module EbooksRenamer
|
|
73
73
|
|
74
74
|
def parse(filename)
|
75
75
|
case File.extname(filename)
|
76
|
-
when
|
76
|
+
when ".epub"
|
77
77
|
Parser.new(EpubParser.parse(filename)).parser
|
78
|
-
when
|
78
|
+
when ".pdf"
|
79
79
|
Parser.new(PdfParser.parse(filename)).parser
|
80
|
-
when
|
80
|
+
when ".mobi"
|
81
81
|
Parser.new(MobiParser.parse(filename)).parser
|
82
82
|
else
|
83
83
|
fail "File type #{File.extname(file)} is not supported"
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "pry"
|
2
2
|
module EbooksRenamer
|
3
3
|
class PdfParser
|
4
4
|
class << self
|
5
5
|
def parse(filename)
|
6
|
-
File.open(filename,
|
6
|
+
File.open(filename, "rb") do |io|
|
7
7
|
reader = PDF::Reader.new(io)
|
8
8
|
if reader && reader.info && reader.info[:Title].present?
|
9
9
|
OpenStruct.new title: reader.info[:Title],
|
@@ -11,7 +11,7 @@ module EbooksRenamer
|
|
11
11
|
pages: reader.page_count
|
12
12
|
end
|
13
13
|
end
|
14
|
-
rescue
|
14
|
+
rescue => e
|
15
15
|
# Note: we skip the file that we can't process
|
16
16
|
# and allow the process to continue
|
17
17
|
puts "Skip file '#{filename}'"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebooks_renamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-05-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -275,7 +275,6 @@ files:
|
|
275
275
|
- lib/ebooks_renamer/mobi_parser.rb
|
276
276
|
- lib/ebooks_renamer/pdf_parser.rb
|
277
277
|
- lib/ebooks_renamer/version.rb
|
278
|
-
- rubocop-todo.yml
|
279
278
|
homepage: https://github.com/agilecreativity/ebooks_renamer
|
280
279
|
licenses:
|
281
280
|
- MIT
|
data/rubocop-todo.yml
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-04-23 16:41:01 +1000 using RuboCop version 0.19.1.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 2
|
9
|
-
# Cop supports --auto-correct.
|
10
|
-
DeprecatedClassMethods:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
# Offense count: 9
|
14
|
-
Documentation:
|
15
|
-
Enabled: false
|
16
|
-
|
17
|
-
# Offense count: 6
|
18
|
-
# Cop supports --auto-correct.
|
19
|
-
EmptyLinesAroundBody:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
# Offense count: 1
|
23
|
-
Eval:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
# Offense count: 2
|
27
|
-
# Configuration parameters: Exclude.
|
28
|
-
FileName:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
# Offense count: 1
|
32
|
-
# Cop supports --auto-correct.
|
33
|
-
IndentationConsistency:
|
34
|
-
Enabled: true
|
35
|
-
|
36
|
-
# Offense count: 2
|
37
|
-
# Cop supports --auto-correct.
|
38
|
-
LeadingCommentSpace:
|
39
|
-
Enabled: false
|
40
|
-
|
41
|
-
# Offense count: 5
|
42
|
-
LineLength:
|
43
|
-
Max: 89
|
44
|
-
|
45
|
-
# Offense count: 1
|
46
|
-
# Configuration parameters: CountComments.
|
47
|
-
MethodLength:
|
48
|
-
Max: 12
|
49
|
-
|
50
|
-
# Offense count: 2
|
51
|
-
# Configuration parameters: NamePrefixBlacklist.
|
52
|
-
PredicateName:
|
53
|
-
Enabled: false
|
54
|
-
|
55
|
-
# Offense count: 1
|
56
|
-
RedundantBegin:
|
57
|
-
Enabled: true
|
58
|
-
|
59
|
-
# Offense count: 1
|
60
|
-
RescueException:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
# Offense count: 2
|
64
|
-
RescueModifier:
|
65
|
-
Enabled: false
|
66
|
-
|
67
|
-
# Offense count: 2
|
68
|
-
# Cop supports --auto-correct.
|
69
|
-
SpaceAfterComma:
|
70
|
-
Enabled: true
|
71
|
-
|
72
|
-
# Offense count: 2
|
73
|
-
# Cop supports --auto-correct.
|
74
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
75
|
-
SpaceBeforeBlockBraces:
|
76
|
-
Enabled: true
|
77
|
-
|
78
|
-
# Offense count: 1
|
79
|
-
# Cop supports --auto-correct.
|
80
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
81
|
-
SpaceInsideBlockBraces:
|
82
|
-
Enabled: true
|
83
|
-
|
84
|
-
# Offense count: 16
|
85
|
-
# Cop supports --auto-correct.
|
86
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
87
|
-
StringLiterals:
|
88
|
-
Enabled: true
|
89
|
-
|
90
|
-
# Offense count: 2
|
91
|
-
UselessAssignment:
|
92
|
-
Enabled: true
|