grim 0.2.3 → 0.2.4

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.
data/lib/grim.rb CHANGED
@@ -27,6 +27,10 @@ module Grim
27
27
  class PathMissing < Grim::Exception
28
28
  end
29
29
 
30
+ # Exception that is raised if Grim::Page#save can't process the page
31
+ class UnprocessablePage < Grim::Exception
32
+ end
33
+
30
34
  # Creates and returns a new instance of Grim::Pdf
31
35
  #
32
36
  # path - a path string or object
data/lib/grim/page.rb CHANGED
@@ -36,12 +36,12 @@ module Grim
36
36
  density = options.fetch(:density, Grim::DENSITY)
37
37
  quality = options.fetch(:quality, Grim::QUALITY)
38
38
 
39
- SafeShell.execute("convert", "-resize", width, "-antialias", "-render",
39
+ output = SafeShell.execute("convert", "-resize", width, "-antialias", "-render",
40
40
  "-quality", quality, "-colorspace", "RGB",
41
41
  "-interlace", "none", "-density", density,
42
42
  "#{@pdf.path}[#{@index}]", path)
43
43
 
44
- File.exists?(path)
44
+ $? == 0 || raise(UnprocessablePage, output)
45
45
  end
46
46
 
47
47
  # Extracts the text from the selected page.
data/lib/grim/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Grim
3
- VERSION = "0.2.3" unless defined?(::Grim::VERSION)
3
+ VERSION = "0.2.4" unless defined?(::Grim::VERSION)
4
4
  end
Binary file
@@ -86,6 +86,15 @@ describe Grim::Page do
86
86
  end
87
87
  end
88
88
 
89
+ describe "#save with an unprocessable PDF" do
90
+ let(:path) { tmp_path("unprocessable.jpg") }
91
+ let(:pdf) { Grim::Pdf.new(fixture_path("unprocessable.pdf")) }
92
+
93
+ it "should raise an error" do
94
+ lambda { pdf[0].save(path) }.should raise_error(Grim::UnprocessablePage, /missing an image filename/)
95
+ end
96
+ end
97
+
89
98
  describe "#text" do
90
99
  it "should return the text from the selected page" do
91
100
  pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grim
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Hoyt
@@ -15,10 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-12 00:00:00 Z
18
+ date: 2011-09-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ name: safe_shell
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
22
24
  none: false
23
25
  requirements:
24
26
  - - ~>
@@ -29,10 +31,8 @@ dependencies:
29
31
  - 0
30
32
  - 0
31
33
  version: 1.0.0
32
- prerelease: false
33
34
  type: :runtime
34
- requirement: *id001
35
- name: safe_shell
35
+ version_requirements: *id001
36
36
  description: Grim is a simple gem for extracting a page from a pdf and converting it to an image as well as extract the text from the page as a string. It basically gives you an easy to use api to ghostscript, imagemagick, and pdftotext specific to this use case.
37
37
  email:
38
38
  - jonmagic@gmail.com
@@ -55,6 +55,7 @@ files:
55
55
  - lib/grim/version.rb
56
56
  - lib/pdf_info.ps
57
57
  - spec/fixtures/smoker.pdf
58
+ - spec/fixtures/unprocessable.pdf
58
59
  - spec/lib/grim/page_spec.rb
59
60
  - spec/lib/grim/pdf_spec.rb
60
61
  - spec/lib/grim_spec.rb
@@ -94,6 +95,7 @@ specification_version: 3
94
95
  summary: Extract slides and text from a PDF.
95
96
  test_files:
96
97
  - spec/fixtures/smoker.pdf
98
+ - spec/fixtures/unprocessable.pdf
97
99
  - spec/lib/grim/page_spec.rb
98
100
  - spec/lib/grim/pdf_spec.rb
99
101
  - spec/lib/grim_spec.rb