ebooks_renamer 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ebooks_renamer.gemspec +2 -2
- data/lib/ebooks_renamer/ebooks_renamer.rb +30 -5
- data/lib/ebooks_renamer/pdf_parser.rb +6 -0
- data/lib/ebooks_renamer/version.rb +1 -1
- metadata +6 -7
- data/lib/ebooks_renamer/parser.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad074d3d9040aed40b72ad5ae49e1a633100f800
|
4
|
+
data.tar.gz: e75c6738ee5f4778a4ffd0fd6868f1758fa0934f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b2d373f25a32ef2072531359a87e8eb41ace95f0aed4f566c2b5bf439d9522fb7fbd99fd98dd39caf32a40b052c20650098364c2069ed286fa6f21ee09d924
|
7
|
+
data.tar.gz: 664d613595420042f56541fe814bcdb45ae7b91f99fc1818a5f81da985f011485d5d209073008f4cd225cc5c22b7314edab79a8350761f77f1fc55acfe78e79c
|
data/ebooks_renamer.gemspec
CHANGED
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency 'pdf-reader', '~> 1.3.3'
|
27
27
|
spec.add_runtime_dependency 'mobi', '~> 1.0.0'
|
28
28
|
spec.add_runtime_dependency 'epubinfo', '~> 0.4.3'
|
29
|
-
spec.add_runtime_dependency 'filename_cleaner', '~> 0.
|
30
|
-
spec.add_runtime_dependency 'code_lister', '~> 0.
|
29
|
+
spec.add_runtime_dependency 'filename_cleaner', '~> 0.1'
|
30
|
+
spec.add_runtime_dependency 'code_lister', '~> 0.1'
|
31
31
|
spec.add_development_dependency 'awesome_print', '~> 1.2'
|
32
32
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
33
33
|
spec.add_development_dependency 'gem-ctags', '~> 1.0'
|
@@ -5,7 +5,9 @@ require 'ostruct'
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'filename_cleaner'
|
7
7
|
require 'code_lister'
|
8
|
-
require_relative '
|
8
|
+
require_relative 'pdf_parser'
|
9
|
+
require_relative 'epub_parser'
|
10
|
+
require_relative 'mobi_parser'
|
9
11
|
module EbooksRenamer
|
10
12
|
CustomError = Class.new(StandardError)
|
11
13
|
class << self
|
@@ -15,13 +17,12 @@ module EbooksRenamer
|
|
15
17
|
# process as many files as possible
|
16
18
|
begin
|
17
19
|
new_name = formatted_name(file, options[:sep_string])
|
18
|
-
prefix = "#{index + 1} of #{files.length}"
|
19
20
|
if file != new_name
|
20
|
-
puts "#{
|
21
|
-
puts "#{
|
21
|
+
puts "#{index + 1} of #{files.length}: Old name: '#{file}'"
|
22
|
+
puts "#{index + 1} of #{files.length}: New name: '#{new_name}'"
|
22
23
|
FileUtils.mv(file, new_name) if options[:commit]
|
23
24
|
else
|
24
|
-
puts "#{
|
25
|
+
puts "#{index + 1} of #{files.length}: Result : '#{file}' is identical so no action taken."
|
25
26
|
end
|
26
27
|
rescue Exception => e
|
27
28
|
puts "Skip file '#{file}'"
|
@@ -56,5 +57,29 @@ module EbooksRenamer
|
|
56
57
|
File.expand_path(file)
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
class Parser
|
62
|
+
attr_reader :parser
|
63
|
+
def initialize(parser)
|
64
|
+
@parser = parser
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse(filename)
|
68
|
+
@parser.parse(filename)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse(filename)
|
73
|
+
case File.extname(filename)
|
74
|
+
when '.epub'
|
75
|
+
Parser.new(EpubParser.parse(filename)).parser
|
76
|
+
when '.pdf'
|
77
|
+
Parser.new(PdfParser.parse(filename)).parser
|
78
|
+
when '.mobi'
|
79
|
+
Parser.new(MobiParser.parse(filename)).parser
|
80
|
+
else
|
81
|
+
fail "File type #{File.extname(file)} is not supported"
|
82
|
+
end
|
83
|
+
end
|
59
84
|
end
|
60
85
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module EbooksRenamer
|
2
3
|
class PdfParser
|
3
4
|
class << self
|
@@ -10,6 +11,11 @@ module EbooksRenamer
|
|
10
11
|
pages: reader.page_count
|
11
12
|
end
|
12
13
|
end
|
14
|
+
rescue Exception => e
|
15
|
+
# Note: we skip the file that we can't process
|
16
|
+
# and allow the process to continue
|
17
|
+
puts "Skip file '#{filename}'"
|
18
|
+
puts "Due to the unexpected error: #{e.message}"
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: '0.1'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: '0.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: code_lister
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.1'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: '0.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: awesome_print
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,7 +273,6 @@ files:
|
|
273
273
|
- lib/ebooks_renamer/epub_parser.rb
|
274
274
|
- lib/ebooks_renamer/logger.rb
|
275
275
|
- lib/ebooks_renamer/mobi_parser.rb
|
276
|
-
- lib/ebooks_renamer/parser.rb
|
277
276
|
- lib/ebooks_renamer/pdf_parser.rb
|
278
277
|
- lib/ebooks_renamer/version.rb
|
279
278
|
- rubocop-todo.yml
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative 'pdf_parser'
|
2
|
-
require_relative 'epub_parser'
|
3
|
-
require_relative 'mobi_parser'
|
4
|
-
module EbooksRenamer
|
5
|
-
class << self
|
6
|
-
|
7
|
-
class Parser
|
8
|
-
attr_reader :parser
|
9
|
-
def initialize(parser)
|
10
|
-
@parser = parser
|
11
|
-
end
|
12
|
-
|
13
|
-
def parse(filename)
|
14
|
-
@parser.parse(filename)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse(filename)
|
19
|
-
case File.extname(filename)
|
20
|
-
when '.epub'
|
21
|
-
Parser.new(EpubParser.parse(filename)).parser
|
22
|
-
when '.pdf'
|
23
|
-
Parser.new(PdfParser.parse(filename)).parser
|
24
|
-
when '.mobi'
|
25
|
-
Parser.new(MobiParser.parse(filename)).parser
|
26
|
-
else
|
27
|
-
fail "File type #{File.extname(file)} is not supported"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|