pdf_info 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pdf_info might be problematic. Click here for more details.

@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGYzNzE5ZTY5NDdmOWNkZmRkZTE5MTgyODk1YjM4ODFjZjY5M2E2Nw==
5
+ data.tar.gz: !binary |-
6
+ NTFiYjlhNGUzYjM0OGM3YTNhZTdmNTg0N2I4N2VlYTMwMDNiZjM2Mg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmEyMjM1NzFjYTRjNjQxNmUzYjk3OTQyYjZjMTc5MTI0ZDU0MmY1M2M1Yjhh
10
+ YzU3OWRiYzQ3MDIyMzdmMTI1YmNmNjE1MmFjNGMwMGU2NGYyZDFlNmVlN2Rk
11
+ Y2FiMGVjNWU3MTExYjczNmIyZTViMWUzNDUyYjc3ZmJkYmExMzk=
12
+ data.tar.gz: !binary |-
13
+ NGI0ZGViZGFjNmM5NmEyMjYzZWQ4ZmVlNGQ2NjA4MjdkNzRlYzcwODVhMjFm
14
+ MTk0ZjQzNzAxMmE0N2U2NjQxZjU1MjFlNjE5M2QxNDY1ZDE4NWQ4MDkzYWVm
15
+ MDIyYjRjMjAwOTUyZjY4NjI2NzI4MGNkYzlkNGMzMGEwNjEzZGE=
@@ -1,17 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.8.7
4
- - 1.9.2
5
4
  - 1.9.3
5
+ - 2.0.0
6
6
  - ruby-head
7
7
  - jruby
8
- - rbx
9
8
  - ree
10
9
 
11
10
  before_install:
12
11
  - sudo apt-get update -qq
13
12
  - sudo apt-get install -qq -y poppler-utils poppler-data
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
@@ -1,3 +1,4 @@
1
+ require 'date' unless defined? DateTime
1
2
  require 'pdf/info/exceptions'
2
3
 
3
4
  module PDF
@@ -51,6 +52,8 @@ module PDF
51
52
  metadata = {}
52
53
  rows.each do |row|
53
54
  pair = row.split(':', 2)
55
+ pair.map!(&:strip)
56
+
54
57
  case pair.first
55
58
  when "Pages"
56
59
  metadata[:page_count] = pair.last.to_i
@@ -63,9 +66,11 @@ module PDF
63
66
  when "PDF version"
64
67
  metadata[:version] = pair.last.to_f
65
68
  when "CreationDate"
66
- metadata[:creation_date] = DateTime.parse(pair.last)
69
+ creation_date = parse_datetime(pair.last)
70
+ metadata[:creation_date] = creation_date if creation_date
67
71
  when "ModDate"
68
- metadata[:modification_date] = DateTime.parse(pair.last)
72
+ modification_date = parse_datetime(pair.last)
73
+ metadata[:modification_date] = modification_date if modification_date
69
74
  when /^Page.*size$/
70
75
  metadata[:pages] ||= []
71
76
  metadata[:pages] << pair.last.scan(/[\d.]+/).map(&:to_f)
@@ -78,5 +83,17 @@ module PDF
78
83
  metadata
79
84
  end
80
85
 
86
+ private
87
+
88
+ def parse_datetime(value)
89
+ DateTime.parse(value)
90
+ rescue
91
+ begin
92
+ DateTime.strptime(value, '%m/%d/%Y %k:%M:%S')
93
+ rescue
94
+ nil
95
+ end
96
+ end
97
+
81
98
  end
82
99
  end
@@ -1,6 +1,6 @@
1
1
  module PDF
2
2
  class Info
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
6
6
 
@@ -87,6 +87,58 @@ describe PDF::Info do
87
87
  end
88
88
  end
89
89
 
90
+ describe ".process_output" do
91
+ subject do
92
+ PDF::Info.new('test.pdf')
93
+ end
94
+
95
+ it "symbolizes all keys" do
96
+ output = "a:foo\nb:bar\nc:baz"
97
+ [:a, :b, :c].each do |key|
98
+ expect(subject.process_output(output)).to have_key key
99
+ expect(subject.process_output(output)).to_not have_key key.to_s
100
+ end
101
+ end
102
+
103
+ it "downcases key" do
104
+ output = "I AM ALL CAPITAL:I STAY ALL CAPITAL"
105
+ expected = {:'i_am_all_capital' => 'I STAY ALL CAPITAL'}
106
+ expect(subject.process_output(output)).to include expected
107
+ end
108
+
109
+ it "replaces whitespace in key with underscore" do
110
+ output = "key with space:value without underscore"
111
+ expected = {:'key_with_space' => 'value without underscore'}
112
+ expect(subject.process_output(output)).to include expected
113
+ end
114
+
115
+ it "strips whitespace from metadata pair" do
116
+ output = " key with space :value without space\nkey without space: value with space "
117
+ expected = {:'key_with_space' => 'value without space', :'key_without_space' => 'value with space'}
118
+ expect(subject.process_output(output)).to include expected
119
+ end
120
+ end
121
+
122
+ describe ".parse_datetime" do
123
+ subject do
124
+ pdf_info = PDF::Info.new('test.pdf')
125
+ pdf_info.stub!(:command).and_return(output('successful.txt'))
126
+ pdf_info
127
+ end
128
+
129
+ it 'parse standard datetime format' do
130
+ expect(subject.send(:parse_datetime, '2001-02-03T04:05:06+07:00')).to be_kind_of DateTime
131
+ end
132
+
133
+ it 'parse american datetime format' do
134
+ expect(subject.send(:parse_datetime, '4/23/2004 18:37:34')).to be_kind_of DateTime
135
+ end
136
+
137
+ it 'return nil if string can not be parsed' do
138
+ expect(subject.send(:parse_datetime, 'asdf')).to be_nil
139
+ end
140
+ end
141
+
90
142
  describe "running on sample.pdf" do
91
143
  subject do
92
144
  PDF::Info.command_path = "pdfinfo"
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tom Taylor
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
11
+ date: 2013-05-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -70,33 +65,26 @@ files:
70
65
  homepage: https://github.com/newspaperclub/pdf_info
71
66
  licenses:
72
67
  - MIT
68
+ metadata: {}
73
69
  post_install_message:
74
70
  rdoc_options: []
75
71
  require_paths:
76
72
  - lib
77
73
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
74
  requirements:
80
75
  - - ! '>='
81
76
  - !ruby/object:Gem::Version
82
77
  version: '0'
83
- segments:
84
- - 0
85
- hash: -1371290085031323010
86
78
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
79
  requirements:
89
80
  - - ! '>='
90
81
  - !ruby/object:Gem::Version
91
82
  version: '0'
92
- segments:
93
- - 0
94
- hash: -1371290085031323010
95
83
  requirements: []
96
84
  rubyforge_project: pdf_info
97
- rubygems_version: 1.8.23
85
+ rubygems_version: 2.0.3
98
86
  signing_key:
99
- specification_version: 3
87
+ specification_version: 4
100
88
  summary: Wraps the pdfinfo command line tool to provide a hash of metadata
101
89
  test_files:
102
90
  - spec/assets/sample.pdf