djvu 0.1.2 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8912813f4af87af1ce19e1ed8350fb95b14f910
4
- data.tar.gz: 8423ecf29fbe65b705a02fae0e4edd1b28cfe8d7
3
+ metadata.gz: 429d5cbf8b922aae12d9834ef45985363abaeb54
4
+ data.tar.gz: d7c37ac6c7ff1593fd293ef554ccfb326c645687
5
5
  SHA512:
6
- metadata.gz: 5318b96fb2bc627c8654358a42c7dfecde04dcfbf275cb83ff4d13c65fe86c49eec1f36bb5b1125f76fda856e4f2b40f12263a14633a595f0687e06d044f5936
7
- data.tar.gz: 792b3510ce5542f41f701907345bfe0aa51a2a71b90db97c92483f7a569af4403caf290aca2f7c20f9094e4fe60938dc9dbf046899b14f8058c14a17f2956ece
6
+ metadata.gz: 16559b6be5719fe4d2124e4f885e8d1b0e8d1a445d4ab7737224fabd31b8c1534085a0c38e28579c3d542750cc6a48d25c795844f2b7ff741d937c7aa21ec9b4
7
+ data.tar.gz: bd9692b0c1951df0e2bb0d3de8774026c49b61d641054fda4a9c777126128e477eb6e54729ebf5301d82984cad4ca6932429420a1dab6ed7be417ebacb42d419
data/README.md CHANGED
@@ -52,12 +52,20 @@ MiniMagick::Image.open('1.ppm').write('1.png')
52
52
  ```
53
53
  ### [djvutxt](http://djvu.sourceforge.net/doc/man/djvutxt.html)
54
54
  ```ruby
55
+ # Extract text layer from page to txt file
55
56
  Djvu.file('Alice_in_Wonderland.djvu').djvutxt(page: 8, output_file: '1.txt')
57
+ # Extract text layer from page to variable
58
+ text = Djvu.file('Alice_in_Wonderland.djvu').djvutxt(page: 8)
56
59
  ```
57
60
  ### [djvudump](http://djvu.sourceforge.net/doc/man/djvudump.html)
58
61
  ```ruby
59
62
  dump = Djvu.file('Alice_in_Wonderland.djvu').djvudump
60
63
  ```
64
+ ### [djvused](http://djvu.sourceforge.net/doc/man/djvused.html)
65
+ ```ruby
66
+ # Getting number of pages in djvu file
67
+ num = Djvu.file('Alice_in_Wonderland.djvu').djvused(e: 'n')
68
+ ```
61
69
 
62
70
  ## Contributing
63
71
 
data/djvu.gemspec CHANGED
@@ -15,7 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features|tmp)/}) || f.match(%r{^(\.rubocop\.yml)$})
18
+ f.match(%r{^(test|spec|features|tmp)/}) \
19
+ || f.match(%r{^(\.rubocop\.yml
20
+ |\.codeclimate\.yml
21
+ |\.gitignore
22
+ |\.rspec
23
+ |\.travis\.yml)$}x)
19
24
  end
20
25
  spec.bindir = "exe"
21
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
data/lib/djvu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Djvu
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/djvu.rb CHANGED
@@ -7,6 +7,10 @@ module Djvu
7
7
  class Exception < ::StandardError
8
8
  end
9
9
 
10
+ # Exception that is raised if no input file.
11
+ class InputFileNotFound < Djvu::Exception
12
+ end
13
+
10
14
  # Exception that is raised if no output file.
11
15
  class OutputFileNotFound < Djvu::Exception
12
16
  end
@@ -15,42 +19,68 @@ module Djvu
15
19
  class UnprocessablePage < Djvu::Exception
16
20
  end
17
21
 
22
+ # Can't process page.
23
+ class MissingRequiredArgument < Djvu::Exception
24
+ end
25
+
18
26
  def self.file(djvufile)
19
- Djvu::File.new(djvufile)
27
+ Djvu::Tools.new(djvufile)
20
28
  end
21
29
 
22
- class File
30
+ class Tools
23
31
  def initialize(djvufile)
24
32
  @djvufile = djvufile
25
33
  self
26
34
  end
27
35
 
28
36
  def ddjvu(options)
29
- raise OutputFileNotFound unless options[:output_file]
37
+ raise(MissingRequiredArgument, '-format is required') unless options[:format]
38
+
39
+ command = []
40
+ command << 'ddjvu'
41
+ command << parse_options(options)
42
+ command << @djvufile
43
+ command << options[:output_file] if options[:output_file]
30
44
 
31
- result, status = Open3.capture2e('ddjvu ' + [parse_options(options), @djvufile, options[:output_file]].join(' '))
45
+ result, status = Open3.capture2e(command.join(' '))
32
46
 
33
47
  status.success? || raise(UnprocessablePage, result)
34
48
  end
35
49
 
36
- def djvutxt(options)
37
- raise OutputFileNotFound unless options[:output_file]
50
+ def djvutxt(options = false)
51
+ command = []
52
+ command << 'djvutxt'
53
+ command << parse_options(options, '--%s=%s') if options
54
+ command << @djvufile
55
+ command << options[:output_file] if options && options[:output_file]
38
56
 
39
- result, status = Open3.capture2e('djvutxt ' + [parse_options(options, "--%s=%s"), @djvufile, options[:output_file]].join(' '))
57
+ result, status = Open3.capture2e(command.join(' '))
40
58
 
41
59
  status.success? || raise(UnprocessablePage, result)
60
+
61
+ result
42
62
  end
43
63
 
44
- def djvudump(options = {})
45
- result, status = Open3.capture2e('djvudump ' + [parse_options(options, "-%s %s"), @djvufile].join(' '))
64
+ def djvudump(options = false)
65
+ command = []
66
+ command << 'djvudump'
67
+ command << parse_options(options, '-%s %s') if options
68
+ command << @djvufile
69
+
70
+ result, status = Open3.capture2e(command.join(' '))
46
71
 
47
72
  status.success? || raise(UnprocessablePage, result)
48
73
 
49
- result unless options[:o]
74
+ result unless options && options[:o]
50
75
  end
51
76
 
52
- def djvused(options = {})
53
- result, status = Open3.capture2e('djvused ' + [parse_options(options, "-%s '%s'"), @djvufile].join(' '))
77
+ def djvused(options = false)
78
+ command = []
79
+ command << 'djvused'
80
+ command << parse_options(options, "-%s '%s'") if options
81
+ command << @djvufile
82
+
83
+ result, status = Open3.capture2e(command.join(' '))
54
84
 
55
85
  status.success? || raise(UnprocessablePage, result)
56
86
 
@@ -59,7 +89,7 @@ module Djvu
59
89
 
60
90
  private
61
91
 
62
- def parse_options(options, pattern = "-%s=%s")
92
+ def parse_options(options, pattern = '-%s=%s')
63
93
  command = []
64
94
  options.each do |key, val|
65
95
  next if key === :output_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djvu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 1v
@@ -73,10 +73,6 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".codeclimate.yml"
77
- - ".gitignore"
78
- - ".rspec"
79
- - ".travis.yml"
80
76
  - Gemfile
81
77
  - LICENSE.txt
82
78
  - README.md
data/.codeclimate.yml DELETED
@@ -1,25 +0,0 @@
1
- ---
2
- engines:
3
- duplication:
4
- enabled: true
5
- config:
6
- languages:
7
- - ruby
8
- - javascript
9
- - python
10
- - php
11
- fixme:
12
- enabled: true
13
- rubocop:
14
- enabled: true
15
- ratings:
16
- paths:
17
- - "**.inc"
18
- - "**.js"
19
- - "**.jsx"
20
- - "**.module"
21
- - "**.php"
22
- - "**.py"
23
- - "**.rb"
24
- exclude_paths:
25
- - spec/
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /Guardfile
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- sudo: true
2
- language: ruby
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.7
7
- - 2.2.1
8
- - 2.2.3
9
- - 2.3.1
10
- before_install:
11
- - sudo apt-get update
12
- - wget http://downloads.sourceforge.net/djvu/djvulibre-3.5.27.tar.gz
13
- - tar -xvzf djvulibre-3.5.27.tar.gz
14
- - rm djvulibre-3.5.27.tar.gz
15
- - cd djvulibre-3.5.27
16
- - sudo ./configure
17
- - sudo make
18
- - sudo make install
19
- - cd ../
20
- - sudo rm -rf djvulibre-3.5.27
21
- - gem install bundler -v 1.13.6
22
- addons:
23
- code_climate:
24
- repo_token: dcdb2b8d67dad3b794f81cdb25ec5c016b677002fadb5296f8ae12c00c789cb8