doc_2_pdf 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e67924d06f3cf9ff055c926783440f3e38b61d94
4
- data.tar.gz: 8b800fae1d3c4575cdaffa270f3f746ada4a5d27
3
+ metadata.gz: ae84925d905241ade8b9027c7cb934ec14c9bbf5
4
+ data.tar.gz: ba81fd65e1f75cc1791cfed854a4ae16c3326031
5
5
  SHA512:
6
- metadata.gz: 3dcde060e8b8bd7e5a7d85b617a1fb67a2766c6d8a18f87aff1878960c6d56e6fcf43114e352e33439ea5df1ba23da5ea69dd132776db7ce4e2ee70701083dac
7
- data.tar.gz: 9beceea911bdfb71b5cb31577b99deb75688a29e631c97748954b62bd797c9f7061b2a6c643815f8c8e2ce997a4fd480911a139362989b0242ffe892965869e1
6
+ metadata.gz: 7a3d2f8d2619a71733b06187595523b50cef32d21a6a90f79d9916724833559891a799e0d92720890ac9a4dd77874183a14fab51ea4966db68c84c8c295176cb
7
+ data.tar.gz: e50e0624a50a5a40c9901ce542c7520c0e8fec5048ecd635ba8ae4b5260b0a88ab01de8b2076591b019a1c8ab7764c189e52c59a1d774630bbfa982ea5274f85
data/README.md CHANGED
@@ -43,6 +43,21 @@ end
43
43
  `convert!` optionally accepts a code block with one argument. This argument (`pdf_path` in the above example) will be a string representing the path of the newly created pdf relative to `pdf_dif` defined at configuration. The folder structure `pdf_dir` will be identical to that of `doc_dir` but for every `.doc`/`.dox` file there will instead be a `.pdf` file with the same name.
44
44
 
45
45
 
46
+ Alternatively a single doc file can be converted to pdf using the `convert_single!` method:
47
+
48
+ ```ruby
49
+ doc_dir = '/some/path/with/doc/files'
50
+ pdf_dir = '/where/to/save/pdf/files'
51
+
52
+ DocPdf.configure doc_dir: doc_dir, pdf_dir: pdf_dir
53
+
54
+ relative_pdf_path = DocPdf.convert_single! File.join(doc_dir, 'My Word Doc.doc')
55
+
56
+ puts File.join pdf_dir, relative_pdf_path
57
+ # => '/where/to/save/pdf/files/My Word Doc.doc/'
58
+ ```
59
+
60
+
46
61
  License
47
62
  -----------------------------
48
63
 
@@ -9,13 +9,29 @@ class DocPdf
9
9
 
10
10
  def self.convert!
11
11
  Dir.glob(File.join(@@doc_dir, '**', '*.{doc,docx}')) do |doc|
12
- pdf_filename = File.basename(doc, '.*')+'.pdf'
13
- relative_path = File.dirname doc.gsub(@@doc_dir, '')
14
- relative_pdf_path = relative_path == '.' ? pdf_filename : File.join(relative_path, pdf_filename)
15
- pdf_path = File.join @@pdf_dir, relative_pdf_path
16
- FileUtils.mkdir_p File.dirname(pdf_path)
17
- Libreconv.convert doc, pdf_path
12
+ relative_pdf_path = convert_doc doc
18
13
  yield(relative_pdf_path) if block_given?
19
14
  end
20
15
  end
16
+
17
+ def self.convert_single! doc
18
+ convert_doc doc
19
+ end
20
+
21
+ def self.doc? file_path
22
+ ['.doc', '.docx'].include? File.extname(file_path)
23
+ end
24
+
25
+ private
26
+
27
+ def self.convert_doc doc
28
+ raise ArgumentError, "Not a .doc/.docx file: #{doc}" unless doc?(doc)
29
+ pdf_filename = File.basename(doc, '.*')+'.pdf'
30
+ relative_path = File.dirname doc.gsub(@@doc_dir, '')
31
+ relative_pdf_path = relative_path == '.' ? pdf_filename : File.join(relative_path, pdf_filename)
32
+ pdf_path = File.join @@pdf_dir, relative_pdf_path
33
+ FileUtils.mkdir_p File.dirname(pdf_path)
34
+ Libreconv.convert doc, pdf_path
35
+ relative_pdf_path
36
+ end
21
37
  end
@@ -1,3 +1,3 @@
1
1
  module Doc2Pdf
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doc_2_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libreconv