stevedore 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
1
  lib/**/*.rb
3
2
  bin/*
3
+ -
4
4
  features/**/*.feature
5
- LICENSE
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.7)
12
+ rake (10.0.4)
13
+ rcov (1.0.0)
14
+ rdoc (3.12.2)
15
+ json (~> 1.4)
16
+ rspec (2.8.0)
17
+ rspec-core (~> 2.8.0)
18
+ rspec-expectations (~> 2.8.0)
19
+ rspec-mocks (~> 2.8.0)
20
+ rspec-core (2.8.0)
21
+ rspec-expectations (2.8.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.1.0)
30
+ jeweler (~> 1.8.4)
31
+ rcov
32
+ rdoc (~> 3.12)
33
+ rspec (~> 2.8.0)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Andrew Carpenter, Critical Juncture LLC
1
+ Copyright (c) 2013 Andrew Carpenter
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -6,14 +6,14 @@ Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimag
6
6
 
7
7
  pdf = Stevedore::Pdf.new('/path/to/file.pdf')
8
8
  pdf.total_pages # => 2
9
-
9
+
10
10
  pdf.images.each do |image|
11
11
  image.page_number
12
12
  image.file_path
13
13
  end
14
-
14
+
15
15
  == Note on Patches/Pull Requests
16
-
16
+
17
17
  * Fork the project.
18
18
  * Make your feature addition or bug fix.
19
19
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -1,41 +1,44 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
2
12
  require 'rake'
3
13
 
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"
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "stevedore"
18
+ gem.homepage = "https://github.com/criticaljuncture/stevedore"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{unload your docs}
21
+ gem.description = %Q{Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.}
22
+ gem.email = "andrew@criticaljuncture.org"
23
+ gem.authors = ["Andrew Carpenter"]
24
+ # dependencies defined in Gemfile
20
25
  end
26
+ Jeweler::RubygemsDotOrgTasks.new
21
27
 
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']
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
26
32
  end
27
33
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
30
35
  spec.pattern = 'spec/**/*_spec.rb'
31
36
  spec.rcov = true
32
37
  end
33
38
 
34
- task :spec => :check_dependencies
35
-
36
39
  task :default => :spec
37
40
 
38
- require 'rake/rdoctask'
41
+ require 'rdoc/task'
39
42
  Rake::RDocTask.new do |rdoc|
40
43
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
44
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/lib/stevedore.rb CHANGED
@@ -1,13 +1,11 @@
1
- require "rubygems" # TODO: remove me
2
- require "activesupport"
3
1
  require "tmpdir"
4
2
 
5
3
  module Stevedore
6
4
  class CommandLineError < StandardError #:nodoc:
7
5
  end
8
-
6
+
9
7
  private
10
-
8
+
11
9
  def self.run(command, expected_outcodes = 0)
12
10
  output = `#{command}`
13
11
  unless [expected_outcodes].flatten.include?($?.exitstatus)
@@ -17,4 +15,4 @@ module Stevedore
17
15
  end
18
16
  end
19
17
 
20
- require "stevedore/pdf"
18
+ require "stevedore/pdf"
data/lib/stevedore/pdf.rb CHANGED
@@ -1,59 +1,65 @@
1
1
  class Stevedore::Pdf
2
2
  attr_reader :file_path
3
-
3
+
4
4
  def initialize(file_path)
5
5
  @file_path = file_path
6
6
  end
7
-
7
+
8
8
  def metadata
9
9
  @metadata ||= Metadata.new(self)
10
10
  end
11
-
12
- delegate :num_pages, :to => :metadata
13
-
11
+
12
+ def num_pages
13
+ metadata.num_pages
14
+ end
15
+
14
16
  class Metadata
15
17
  require 'yaml'
16
-
18
+
17
19
  def initialize(pdf)
18
20
  @pdf = pdf
19
21
  output = Stevedore.run("pdfinfo #{@pdf.file_path}")
20
- @raw_metadata = YAML::load(output)
22
+ @raw_metadata = output.split("\n").reduce(Hash.new) do |metadata, line|
23
+ name, val = line.split(/: +/,2)
24
+ metadata[name] = val
25
+ metadata
26
+ end
21
27
  end
22
-
28
+
23
29
  def num_pages
24
30
  @raw_metadata["Pages"].to_i
25
31
  end
26
32
  end
27
-
33
+
28
34
  def images(base_dir = tmp_dir)
29
35
  @images ||= Image.extract_all(self, base_dir)
30
36
  end
31
-
37
+
32
38
  def tmp_dir
33
39
  @dir ||= Dir.mktmpdir
34
40
  end
35
-
41
+
36
42
  class Image
37
43
  attr_reader :file_path, :page_number
38
-
44
+
39
45
  def self.extract_all(pdf, base_dir)
40
46
  @pdf = pdf
41
47
  images = []
42
48
  (1..pdf.num_pages).each do |page_number|
43
49
  base_name = "#{base_dir}/page-#{sprintf("%00d", page_number)}"
44
50
  Stevedore.run("pdfimages -f #{page_number} -l #{page_number} #{@pdf.file_path} #{base_name}")
45
-
51
+
46
52
  Dir.glob("#{base_name}*").sort.each do |file_path|
47
53
  images << new(file_path, page_number)
48
54
  end
49
55
  end
50
-
56
+
51
57
  images
52
58
  end
53
-
59
+
54
60
  def initialize(file_path, page_number)
55
61
  @file_path = file_path
56
62
  @page_number = page_number
57
63
  end
58
64
  end
59
- end
65
+ end
data/spec/pdf_spec.rb CHANGED
@@ -1,28 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "pdf_instance" do
3
+ describe Stevedore::Pdf do
4
4
  before :each do
5
5
  @file_path = File.expand_path(File.dirname(__FILE__) + '/test.pdf')
6
6
  @pdf = Stevedore::Pdf.new(@file_path)
7
7
  end
8
-
9
- describe ".file_path" do
8
+
9
+ describe '#file_path' do
10
10
  it "should return the file path" do
11
11
  @pdf.file_path.should == @file_path
12
12
  end
13
13
  end
14
14
 
15
- describe ".num_pages" do
15
+ describe '#num_pages' do
16
16
  it "should return the number of pages" do
17
17
  @pdf.num_pages.should == 2
18
18
  end
19
19
  end
20
-
21
- describe ".images" do
20
+
21
+ describe '#images' do
22
22
  it "should return 4 images" do
23
23
  @pdf.images.size.should == 4
24
24
  end
25
-
25
+
26
26
  it "should return 2 images for page 1 and 2 images for page 2" do
27
27
  @pdf.images[0].page_number.should == 1
28
28
  @pdf.images[1].page_number.should == 1
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,12 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
3
4
  require 'stevedore'
4
- require 'spec'
5
- require 'spec/autorun'
6
5
 
7
- Spec::Runner.configure do |config|
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
8
11
 
9
12
  end
data/stevedore.gemspec CHANGED
@@ -1,60 +1,66 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{stevedore}
8
- s.version = "0.0.1"
7
+ s.name = "stevedore"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
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}
12
+ s.date = "2013-05-10"
13
+ s.description = "Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`."
14
+ s.email = "andrew@criticaljuncture.org"
15
15
  s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
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 = [
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/stevedore.rb",
29
+ "lib/stevedore/pdf.rb",
40
30
  "spec/pdf_spec.rb",
41
- "spec/spec_helper.rb"
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "spec/test.pdf",
34
+ "stevedore.gemspec"
42
35
  ]
36
+ s.homepage = "https://github.com/criticaljuncture/stevedore"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.24"
40
+ s.summary = "unload your docs"
43
41
 
44
42
  if s.respond_to? :specification_version then
45
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
43
  s.specification_version = 3
47
44
 
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"])
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
51
  else
52
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
- s.add_dependency(%q<activesupport>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
54
57
  end
55
58
  else
56
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
- s.add_dependency(%q<activesupport>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
58
64
  end
59
65
  end
60
66
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stevedore
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 0
8
8
  - 1
9
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Andrew Carpenter
@@ -14,48 +15,100 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-06 00:00:00 -07:00
18
- default_executable:
18
+ date: 2013-05-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 47
27
+ segments:
28
+ - 2
29
+ - 8
30
+ - 0
31
+ version: 2.8.0
32
+ version_requirements: *id001
21
33
  name: rspec
22
34
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
24
39
  requirements:
25
- - - ">="
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 31
43
+ segments:
44
+ - 3
45
+ - 12
46
+ version: "3.12"
47
+ version_requirements: *id002
48
+ name: rdoc
49
+ prerelease: false
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
26
56
  - !ruby/object:Gem::Version
57
+ hash: 19
27
58
  segments:
28
59
  - 1
29
- - 2
30
- - 9
31
- version: 1.2.9
60
+ - 1
61
+ - 0
62
+ version: 1.1.0
63
+ version_requirements: *id003
64
+ name: bundler
65
+ prerelease: false
32
66
  type: :development
33
- version_requirements: *id001
34
67
  - !ruby/object:Gem::Dependency
35
- name: activesupport
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 63
74
+ segments:
75
+ - 1
76
+ - 8
77
+ - 4
78
+ version: 1.8.4
79
+ version_requirements: *id004
80
+ name: jeweler
36
81
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
38
86
  requirements:
39
87
  - - ">="
40
88
  - !ruby/object:Gem::Version
89
+ hash: 3
41
90
  segments:
42
91
  - 0
43
92
  version: "0"
44
- type: :runtime
45
- version_requirements: *id002
93
+ version_requirements: *id005
94
+ name: rcov
95
+ prerelease: false
96
+ type: :development
46
97
  description: Get metadata about PDFs and extract full-quality images. Wrapper around `pdfimages` and `pdfinfo`.
47
- email: info@criticaljuncture.org
98
+ email: andrew@criticaljuncture.org
48
99
  executables: []
49
100
 
50
101
  extensions: []
51
102
 
52
103
  extra_rdoc_files:
53
- - LICENSE
104
+ - LICENSE.txt
54
105
  - README.rdoc
55
106
  files:
56
107
  - .document
57
- - .gitignore
58
- - LICENSE
108
+ - .rspec
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
59
112
  - README.rdoc
60
113
  - Rakefile
61
114
  - VERSION
@@ -66,36 +119,38 @@ files:
66
119
  - spec/spec_helper.rb
67
120
  - spec/test.pdf
68
121
  - stevedore.gemspec
69
- has_rdoc: true
70
- homepage: http://github.com/criticaljuncture/stevedore
71
- licenses: []
72
-
122
+ homepage: https://github.com/criticaljuncture/stevedore
123
+ licenses:
124
+ - MIT
73
125
  post_install_message:
74
- rdoc_options:
75
- - --charset=UTF-8
126
+ rdoc_options: []
127
+
76
128
  require_paths:
77
129
  - lib
78
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
79
132
  requirements:
80
133
  - - ">="
81
134
  - !ruby/object:Gem::Version
135
+ hash: 3
82
136
  segments:
83
137
  - 0
84
138
  version: "0"
85
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
86
141
  requirements:
87
142
  - - ">="
88
143
  - !ruby/object:Gem::Version
144
+ hash: 3
89
145
  segments:
90
146
  - 0
91
147
  version: "0"
92
148
  requirements: []
93
149
 
94
150
  rubyforge_project:
95
- rubygems_version: 1.3.6
151
+ rubygems_version: 1.8.24
96
152
  signing_key:
97
153
  specification_version: 3
98
- summary: Unload your docs
99
- test_files:
100
- - spec/pdf_spec.rb
101
- - spec/spec_helper.rb
154
+ summary: unload your docs
155
+ test_files: []
156
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
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