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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21051173833bb0897f42a45e1bed1171a818b102
4
- data.tar.gz: 69b5503d410a3056cb243dd8723eb4d94f0897e8
3
+ metadata.gz: ad074d3d9040aed40b72ad5ae49e1a633100f800
4
+ data.tar.gz: e75c6738ee5f4778a4ffd0fd6868f1758fa0934f
5
5
  SHA512:
6
- metadata.gz: 6ceadb1eb92fc29760902ddd8ed083a6d4877263ac91c9cfec4140e25b4f7d593dc01c9bab9a14c6bc569c132b87db59071d6a846742baddd29e5986d457c46c
7
- data.tar.gz: 90002d6ce91160672bc87fb2055aeb09bb8eb3861f39870e19cce4f122332126f1b0409377be2dc93939823a349481fa42c63345529bdc2717bf3fc2c1759ea1
6
+ metadata.gz: 18b2d373f25a32ef2072531359a87e8eb41ace95f0aed4f566c2b5bf439d9522fb7fbd99fd98dd39caf32a40b052c20650098364c2069ed286fa6f21ee09d924
7
+ data.tar.gz: 664d613595420042f56541fe814bcdb45ae7b91f99fc1818a5f81da985f011485d5d209073008f4cd225cc5c22b7314edab79a8350761f77f1fc55acfe78e79c
@@ -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.0.3'
30
- spec.add_runtime_dependency 'code_lister', '~> 0.0.8'
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 'parser'
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 "#{prefix}: old name : '#{file}'"
21
- puts "#{prefix}: new name : '#{new_name}'"
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 "#{prefix}: unchanded: '#{file}' is identical so no action taken."
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
@@ -1,3 +1,3 @@
1
1
  module EbooksRenamer
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  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.5
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-04 00:00:00.000000000 Z
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.0.3
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.0.3
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.0.8
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.0.8
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