mupdf 0.1.0 → 0.3.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
  SHA256:
3
- metadata.gz: ad445c502c69e3143bf400a94e9c3e1935dce191e58f7585aa8fdd164ac8e744
4
- data.tar.gz: 84f2f037ab19c276d719bcc85b9dbc13dba28c4107e11b71702e55b31af3f788
3
+ metadata.gz: 025aace876d1fc5f6ba89c7e94fb7a618b645c5011d1eb7d3923252ca1643693
4
+ data.tar.gz: 9cc27d161818550e2b3290933652be4c1b8474f550f7c6f71a59eda5af4f02cc
5
5
  SHA512:
6
- metadata.gz: d5d322ac79969df1cbb4a454a9d0df8298a632727caf82b4b4d93515f650b53162e3031bfd0be30dbd93dd97e1b50ed15cf844f360c216916af6d7245456db7f
7
- data.tar.gz: 043c241a4c8cac55ac0597ccc46a9fb940bc8b62f5461d6fd6c66d9ebe8c6095300c2780ef8b52a00882b07ab87c26415739157ce4d597204f3ba2515dfb4d5c
6
+ metadata.gz: baf0ad502de63e12d938481d8944a96091a74f85e5d42189bcac9b7b0afb5b262f133e70eae434ac3f129349105262ececeff6e3feadbc037f4be14fd7127502
7
+ data.tar.gz: 90a9bedd5984280f820b76bbbcab596bea290bdb79c6e699cf029898569cc006e23e7c26ea1877a95d8406a025e2dd70f2faec675f8aab0af2b143d9fa76352f
data/Gemfile CHANGED
@@ -10,4 +10,5 @@ gem 'rspec_junit_formatter'
10
10
  gem 'rubocop'
11
11
  gem 'rubocop-rake'
12
12
  gem 'rubocop-rspec'
13
+ gem 'simplecov'
13
14
  gem 'yard'
data/README.md CHANGED
@@ -1 +1,32 @@
1
1
  # MuPDF
2
+
3
+ [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ksylvest/mupdf/blob/main/LICENSE)
4
+ [![RubyGems](https://img.shields.io/gem/v/mupdf)](https://rubygems.org/gems/mupdf)
5
+ [![GitHub](https://img.shields.io/badge/github-repo-blue.svg)](https://github.com/ksylvest/mupdf)
6
+ [![Yard](https://img.shields.io/badge/docs-site-blue.svg)](https://mupdf.ksylvest.com)
7
+ [![CircleCI](https://img.shields.io/circleci/build/github/ksylvest/mupdf)](https://circleci.com/gh/ksylvest/mupdf)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ gem install mupdf
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Document
18
+
19
+ A `MuPDF::Document` wraps for a file:
20
+
21
+ ```ruby
22
+ document = MuPDF::Document.new('./file.pdf')
23
+ ```
24
+
25
+ #### Info
26
+
27
+ The `info` command displays information about a document such as the number of pages:
28
+
29
+ ```ruby
30
+ info = document.info
31
+ info.pages # e.g. 2
32
+ ```
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuPDF
4
+ # An error raised when an mutool command errors.
5
+ class CommandError < StandardError
6
+ # @param cmd [String]
7
+ # @param result [String]
8
+ # @param status [Process::Status]
9
+ def initialize(cmd:, result:, status:)
10
+ super("cmd=#{cmd.inspect} result=#{result.inspect} status=#{status.inspect}")
11
+ @cmd = cmd
12
+ @result = result
13
+ @status = status
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuPDF
4
+ # A wrapper for a PDF document allowing for MuPDF APIs.
5
+ class Document
6
+ # @param pathname [Pathname]
7
+ def initialize(pathname)
8
+ @pathname = pathname
9
+ end
10
+
11
+ # @raise [MuPDF::CommandError]
12
+ #
13
+ # @return [MuPDF::Info]
14
+ def info
15
+ @info ||= begin
16
+ result = MuPDF.mutool('info', String(@pathname))
17
+ MuPDF::Info.parse(result)
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/mupdf/info.rb ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuPDF
4
+ # A wrapper for the result of a `mutool info ...` command.
5
+ class Info
6
+ PARSE_REGEX = /^Pages: (?<pages>\d+)$/
7
+
8
+ # @!attribute description
9
+ # @return [String] The description of the task.
10
+ attr_reader :pages
11
+
12
+ # @param text [String]
13
+ #
14
+ # @return [MuPDF::Info]
15
+ def self.parse(text)
16
+ match = text.match(PARSE_REGEX)
17
+ new(pages: Integer(match[:pages]))
18
+ end
19
+
20
+ # @param pages [Integer]
21
+ def initialize(pages:)
22
+ @pages = pages
23
+ end
24
+ end
25
+ end
data/lib/mupdf/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuPDF
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/mupdf.rb CHANGED
@@ -1,11 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
3
4
  require 'zeitwerk'
4
5
 
5
6
  loader = Zeitwerk::Loader.for_gem
6
7
  loader.inflector.inflect 'mupdf' => 'MuPDF'
7
8
  loader.setup
8
9
 
10
+ # An interface to [MuPDF](https://mupdf.com/) for managing PDFs.
9
11
  module MuPDF
10
12
  class Error < StandardError; end
13
+
14
+ # @usage
15
+ # MuPDF.mutool('info', 'file.pdf')
16
+ #
17
+ # @param cmd [Array<String>] e.g. ['info', 'file.pdf']
18
+ # @raise [ToolError]
19
+ #
20
+ # @return [String]
21
+ def self.mutool(*cmd)
22
+ result, status = Open3.capture2e('mutool', *cmd)
23
+ raise CommandError.new(cmd:, result:, status:) unless status.success?
24
+
25
+ result
26
+ end
11
27
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mupdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2025-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: open3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: zeitwerk
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -36,6 +50,9 @@ files:
36
50
  - bin/console
37
51
  - bin/setup
38
52
  - lib/mupdf.rb
53
+ - lib/mupdf/command_error.rb
54
+ - lib/mupdf/document.rb
55
+ - lib/mupdf/info.rb
39
56
  - lib/mupdf/version.rb
40
57
  homepage: https://github.com/ksylvest/mupdf
41
58
  licenses:
@@ -43,10 +60,10 @@ licenses:
43
60
  metadata:
44
61
  rubygems_mfa_required: 'true'
45
62
  homepage_uri: https://github.com/ksylvest/mupdf
46
- source_code_uri: https://github.com/ksylvest/mupdf/tree/v0.1.0
47
- changelog_uri: https://github.com/ksylvest/mupdf/releases/tag/v0.1.0
63
+ source_code_uri: https://github.com/ksylvest/mupdf/tree/v0.3.0
64
+ changelog_uri: https://github.com/ksylvest/mupdf/releases/tag/v0.3.0
48
65
  documentation_uri: https://mupdf.ksylvest.com/
49
- post_install_message:
66
+ post_install_message:
50
67
  rdoc_options: []
51
68
  require_paths:
52
69
  - lib
@@ -61,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
78
  - !ruby/object:Gem::Version
62
79
  version: '0'
63
80
  requirements: []
64
- rubygems_version: 3.5.22
65
- signing_key:
81
+ rubygems_version: 3.5.23
82
+ signing_key:
66
83
  specification_version: 4
67
84
  summary: A library for interacting with MuPDF.
68
85
  test_files: []