mutool 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 58df61e7c3260c94063b6caef9d0c5c642cb2ba58e3b5fb5d89f17405d1f7b68
4
- data.tar.gz: 87144bc9def89aa263a066be49b18aa03e65e64d8efd9369aa4d60e57555f1f9
3
+ metadata.gz: d1818977b9db239383e635158a3f137f30e31f0c8ee3abd5bbb6b2664786b8f4
4
+ data.tar.gz: 526e84ad9e332f9cd63a9674b66a3196342350664c593be1482fde3b9ec7d383
5
5
  SHA512:
6
- metadata.gz: 567f38539714e7eef702cb521a1a394c721737ca5e060cd3c4fe7f5911dfeae1d33f16a633b644513e599e85654d179679447922d1e0d56fdbbf57c24fe51099
7
- data.tar.gz: ed669c4197980dcee0a84d496199cedf43a290a0f071e01d9243daaf3e4d38e498eacb4856b9a76319e8c55a938c2f2df34c4c03b893caa4e05ba2000c9e0874
6
+ metadata.gz: 178493fed1ace40da1fb179422467842e3b5b92c46645f5c647d5c42569d5346263f8afbd6c01f3e1005e98a0e982cd6ddb7e8401330ee5cbaa04d7931d0e8d9
7
+ data.tar.gz: c383030249c29107dae74a386b36cf64405576df79006cb7f8d306edc2bbd87adf5d1066759631e5cbbcb1b6951658db522d53f128d7a08449adc46968779683
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mutool (0.1.1)
4
+ mutool (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,23 +1,48 @@
1
1
  require 'mutool/version'
2
+ require 'thread'
3
+ require 'open3'
2
4
 
3
5
  class Mutool
4
6
  class << Mutool
7
+ attr_accessor :mutool_path, :has_mutool
8
+
9
+ def has_mutool?
10
+ @has_mutool ||= run([mutool_path]).exitstatus == 1
11
+ end
12
+
5
13
  def flags(ops = {})
6
14
  ops.map { |key, value| ["-#{key}", value] }
7
15
  end
8
16
 
17
+ def version
18
+ raise 'mutool not found' unless has_mutool?
19
+ @version ||= version_str.gsub("\n", '').split(' ').last
20
+ end
21
+
9
22
  # Reference: https://mupdf.com/docs/manual-mutool-convert.html
10
23
  def convert(input, pages='1-N', ops)
11
- run(['mutool', 'convert', flags(ops), input, pages].flatten)
24
+ raise 'mutool not found' unless has_mutool?
25
+ run([mutool_path, 'convert', flags(ops), input, pages].flatten)
12
26
  end
13
27
 
14
28
  # https://mupdf.com/docs/manual-mutool-clean.html
15
29
  def clean(input, output, pages='1-N', ops)
16
- run(['mutool', 'clean', flags(ops), input, output, pages].flatten)
30
+ raise 'mutool not found' unless has_mutool?
31
+ run([mutool_path, 'clean', flags(ops), input, output, pages].flatten)
17
32
  end
18
33
 
19
34
  private
20
35
 
36
+ def version_str
37
+ _, _, stderr, thread = Open3.popen3('mutool -v')
38
+ thread.join
39
+ stderr.read
40
+ end
41
+
42
+ def mutool_path
43
+ @mutool_path ||= ENV["MUTOOL_PATH"] || 'mutool'
44
+ end
45
+
21
46
  def run(command = [])
22
47
  system(*command, out: File::NULL, err: File::NULL)
23
48
  $?
@@ -1,3 +1,3 @@
1
1
  class Mutool
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marlon Henry Schweigert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-06 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler