stevedore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andrew Carpenter, Critical Juncture LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ = Stevedore - Unload your docs
2
+
3
+ Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.
4
+
5
+ == Usage
6
+
7
+ pdf = Stevedore::Pdf.new('/path/to/file.pdf')
8
+ pdf.total_pages # => 2
9
+
10
+ pdf.images.each do |image|
11
+ image.page_number
12
+ image.file_path
13
+ end
14
+
15
+ == Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send us a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010 Andrew Carpenter, Critical Juncture LLC. See LICENSE for details.
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "stevedore"
8
+ gem.summary = %Q{Unload your docs}
9
+ gem.description = %Q{Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.}
10
+ gem.email = "info@criticaljuncture.org"
11
+ gem.homepage = "http://github.com/criticaljuncture/stevedore"
12
+ gem.authors = ["Andrew Carpenter"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency 'activesupport'
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "stevedore #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,20 @@
1
+ require "rubygems" # TODO: remove me
2
+ require "activesupport"
3
+ require "tmpdir"
4
+
5
+ module Stevedore
6
+ class CommandLineError < StandardError #:nodoc:
7
+ end
8
+
9
+ private
10
+
11
+ def self.run(command, expected_outcodes = 0)
12
+ output = `#{command}`
13
+ unless [expected_outcodes].flatten.include?($?.exitstatus)
14
+ raise CommandLineError, "Error while running #{command}"
15
+ end
16
+ output
17
+ end
18
+ end
19
+
20
+ require "stevedore/pdf"
@@ -0,0 +1,59 @@
1
+ class Stevedore::Pdf
2
+ attr_reader :file_path
3
+
4
+ def initialize(file_path)
5
+ @file_path = file_path
6
+ end
7
+
8
+ def metadata
9
+ @metadata ||= Metadata.new(self)
10
+ end
11
+
12
+ delegate :num_pages, :to => :metadata
13
+
14
+ class Metadata
15
+ require 'yaml'
16
+
17
+ def initialize(pdf)
18
+ @pdf = pdf
19
+ output = Stevedore.run("pdfinfo #{@pdf.file_path}")
20
+ @raw_metadata = YAML::load(output)
21
+ end
22
+
23
+ def num_pages
24
+ @raw_metadata["Pages"].to_i
25
+ end
26
+ end
27
+
28
+ def images(base_dir = tmp_dir)
29
+ @images ||= Image.extract_all(self, base_dir)
30
+ end
31
+
32
+ def tmp_dir
33
+ @dir ||= Dir.mktmpdir
34
+ end
35
+
36
+ class Image
37
+ attr_reader :file_path, :page_number
38
+
39
+ def self.extract_all(pdf, base_dir)
40
+ @pdf = pdf
41
+ images = []
42
+ (1..pdf.num_pages).each do |page_number|
43
+ base_name = "#{base_dir}/page-#{sprintf("%00d", page_number)}"
44
+ Stevedore.run("pdfimages -f #{page_number} -l #{page_number} #{@pdf.file_path} #{base_name}")
45
+
46
+ Dir.glob("#{base_name}*").sort.each do |file_path|
47
+ images << new(file_path, page_number)
48
+ end
49
+ end
50
+
51
+ images
52
+ end
53
+
54
+ def initialize(file_path, page_number)
55
+ @file_path = file_path
56
+ @page_number = page_number
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "pdf_instance" do
4
+ before :each do
5
+ @file_path = File.expand_path(File.dirname(__FILE__) + '/test.pdf')
6
+ @pdf = Stevedore::Pdf.new(@file_path)
7
+ end
8
+
9
+ describe ".file_path" do
10
+ it "should return the file path" do
11
+ @pdf.file_path.should == @file_path
12
+ end
13
+ end
14
+
15
+ describe ".num_pages" do
16
+ it "should return the number of pages" do
17
+ @pdf.num_pages.should == 2
18
+ end
19
+ end
20
+
21
+ describe ".images" do
22
+ it "should return 4 images" do
23
+ @pdf.images.size.should == 4
24
+ end
25
+
26
+ it "should return 2 images for page 1 and 2 images for page 2" do
27
+ @pdf.images[0].page_number.should == 1
28
+ @pdf.images[1].page_number.should == 1
29
+ @pdf.images[2].page_number.should == 2
30
+ @pdf.images[3].page_number.should == 2
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'stevedore'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
Binary file
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{stevedore}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew Carpenter"]
12
+ s.date = %q{2010-04-06}
13
+ s.description = %q{Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.}
14
+ s.email = %q{info@criticaljuncture.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/stevedore.rb",
27
+ "lib/stevedore/pdf.rb",
28
+ "spec/pdf_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb",
31
+ "spec/test.pdf",
32
+ "stevedore.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/criticaljuncture/stevedore}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Unload your docs}
39
+ s.test_files = [
40
+ "spec/pdf_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<activesupport>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<activesupport>, [">= 0"])
58
+ end
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stevedore
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Andrew Carpenter
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-06 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.
47
+ email: info@criticaljuncture.org
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - lib/stevedore.rb
63
+ - lib/stevedore/pdf.rb
64
+ - spec/pdf_spec.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - spec/test.pdf
68
+ - stevedore.gemspec
69
+ has_rdoc: true
70
+ homepage: http://github.com/criticaljuncture/stevedore
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Unload your docs
99
+ test_files:
100
+ - spec/pdf_spec.rb
101
+ - spec/spec_helper.rb