ebooks_renamer 0.0.4 → 0.0.5

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: e9e270dd18edb25346badcb75bb5e7b45abe42c9
4
- data.tar.gz: 474853d02787a9e64f8d4259145a82106aee0b2f
3
+ metadata.gz: 21051173833bb0897f42a45e1bed1171a818b102
4
+ data.tar.gz: 69b5503d410a3056cb243dd8723eb4d94f0897e8
5
5
  SHA512:
6
- metadata.gz: 79ac4c29ceec9bed3ef163a5302022b34232535fa2f5c4c57b9c80e9de9667eb6581e35062cd8240b8ce0eca18423f9802f9228ecae38a093bf0e74ddc7cb56f
7
- data.tar.gz: 6cfaa16ab0fe43d1e13161460fb2e347d4c7397e194926a2480507ad3be99237f502cc050d784019e4ea0715c0902aa1bed5be4387ff1d624dd2ed40dc2ab4f6
6
+ metadata.gz: 6ceadb1eb92fc29760902ddd8ed083a6d4877263ac91c9cfec4140e25b4f7d593dc01c9bab9a14c6bc569c132b87db59071d6a846742baddd29e5986d457c46c
7
+ data.tar.gz: 90002d6ce91160672bc87fb2055aeb09bb8eb3861f39870e19cce4f122332126f1b0409377be2dc93939823a349481fa42c63345529bdc2717bf3fc2c1759ea1
@@ -5,9 +5,7 @@ require 'ostruct'
5
5
  require 'fileutils'
6
6
  require 'filename_cleaner'
7
7
  require 'code_lister'
8
- require_relative 'pdf_parser'
9
- require_relative 'epub_parser'
10
- require_relative 'mobi_parser'
8
+ require_relative 'parser'
11
9
  module EbooksRenamer
12
10
  CustomError = Class.new(StandardError)
13
11
  class << self
@@ -17,12 +15,13 @@ module EbooksRenamer
17
15
  # process as many files as possible
18
16
  begin
19
17
  new_name = formatted_name(file, options[:sep_string])
18
+ prefix = "#{index + 1} of #{files.length}"
20
19
  if file != new_name
21
- puts "#{index + 1} of #{files.length}: Old name: '#{file}'"
22
- puts "#{index + 1} of #{files.length}: New name: '#{new_name}'"
20
+ puts "#{prefix}: old name : '#{file}'"
21
+ puts "#{prefix}: new name : '#{new_name}'"
23
22
  FileUtils.mv(file, new_name) if options[:commit]
24
23
  else
25
- puts "#{index + 1} of #{files.length}: Result : '#{file}' is identical so no action taken."
24
+ puts "#{prefix}: unchanded: '#{file}' is identical so no action taken."
26
25
  end
27
26
  rescue Exception => e
28
27
  puts "Skip file '#{file}'"
@@ -57,29 +56,5 @@ module EbooksRenamer
57
56
  File.expand_path(file)
58
57
  end
59
58
  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
84
59
  end
85
60
  end
@@ -0,0 +1,31 @@
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
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  module EbooksRenamer
3
2
  class PdfParser
4
3
  class << self
@@ -11,11 +10,6 @@ module EbooksRenamer
11
10
  pages: reader.page_count
12
11
  end
13
12
  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}"
19
13
  end
20
14
  end
21
15
  end
@@ -1,3 +1,3 @@
1
1
  module EbooksRenamer
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebooks_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
@@ -273,6 +273,7 @@ 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
276
277
  - lib/ebooks_renamer/pdf_parser.rb
277
278
  - lib/ebooks_renamer/version.rb
278
279
  - rubocop-todo.yml