rtf_filter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CDDL-LICENSE ADDED
@@ -0,0 +1,382 @@
1
+ Copyright PS Computer Services Ltd 2003-2011
2
+
3
+ COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
4
+
5
+ 1. Definitions.
6
+
7
+ 1.1. "Contributor" means each individual or entity that
8
+ creates or contributes to the creation of Modifications.
9
+
10
+ 1.2. "Contributor Version" means the combination of the
11
+ Original Software, prior Modifications used by a
12
+ Contributor (if any), and the Modifications made by that
13
+ particular Contributor.
14
+
15
+ 1.3. "Covered Software" means (a) the Original Software, or
16
+ (b) Modifications, or (c) the combination of files
17
+ containing Original Software with files containing
18
+ Modifications, in each case including portions thereof.
19
+
20
+ 1.4. "Executable" means the Covered Software in any form
21
+ other than Source Code.
22
+
23
+ 1.5. "Initial Developer" means the individual or entity
24
+ that first makes Original Software available under this
25
+ License.
26
+
27
+ 1.6. "Larger Work" means a work which combines Covered
28
+ Software or portions thereof with code not governed by the
29
+ terms of this License.
30
+
31
+ 1.7. "License" means this document.
32
+
33
+ 1.8. "Licensable" means having the right to grant, to the
34
+ maximum extent possible, whether at the time of the initial
35
+ grant or subsequently acquired, any and all of the rights
36
+ conveyed herein.
37
+
38
+ 1.9. "Modifications" means the Source Code and Executable
39
+ form of any of the following:
40
+
41
+ A. Any file that results from an addition to,
42
+ deletion from or modification of the contents of a
43
+ file containing Original Software or previous
44
+ Modifications;
45
+
46
+ B. Any new file that contains any part of the
47
+ Original Software or previous Modification; or
48
+
49
+ C. Any new file that is contributed or otherwise made
50
+ available under the terms of this License.
51
+
52
+ 1.10. "Original Software" means the Source Code and
53
+ Executable form of computer software code that is
54
+ originally released under this License.
55
+
56
+ 1.11. "Patent Claims" means any patent claim(s), now owned
57
+ or hereafter acquired, including without limitation,
58
+ method, process, and apparatus claims, in any patent
59
+ Licensable by grantor.
60
+
61
+ 1.12. "Source Code" means (a) the common form of computer
62
+ software code in which modifications are made and (b)
63
+ associated documentation included in or with such code.
64
+
65
+ 1.13. "You" (or "Your") means an individual or a legal
66
+ entity exercising rights under, and complying with all of
67
+ the terms of, this License. For legal entities, "You"
68
+ includes any entity which controls, is controlled by, or is
69
+ under common control with You. For purposes of this
70
+ definition, "control" means (a) the power, direct or
71
+ indirect, to cause the direction or management of such
72
+ entity, whether by contract or otherwise, or (b) ownership
73
+ of more than fifty percent (50%) of the outstanding shares
74
+ or beneficial ownership of such entity.
75
+
76
+ 2. License Grants.
77
+
78
+ 2.1. The Initial Developer Grant.
79
+
80
+ Conditioned upon Your compliance with Section 3.1 below and
81
+ subject to third party intellectual property claims, the
82
+ Initial Developer hereby grants You a world-wide,
83
+ royalty-free, non-exclusive license:
84
+
85
+ (a) under intellectual property rights (other than
86
+ patent or trademark) Licensable by Initial Developer,
87
+ to use, reproduce, modify, display, perform,
88
+ sublicense and distribute the Original Software (or
89
+ portions thereof), with or without Modifications,
90
+ and/or as part of a Larger Work; and
91
+
92
+ (b) under Patent Claims infringed by the making,
93
+ using or selling of Original Software, to make, have
94
+ made, use, practice, sell, and offer for sale, and/or
95
+ otherwise dispose of the Original Software (or
96
+ portions thereof).
97
+
98
+ (c) The licenses granted in Sections 2.1(a) and (b)
99
+ are effective on the date Initial Developer first
100
+ distributes or otherwise makes the Original Software
101
+ available to a third party under the terms of this
102
+ License.
103
+
104
+ (d) Notwithstanding Section 2.1(b) above, no patent
105
+ license is granted: (1) for code that You delete from
106
+ the Original Software, or (2) for infringements
107
+ caused by: (i) the modification of the Original
108
+ Software, or (ii) the combination of the Original
109
+ Software with other software or devices.
110
+
111
+ 2.2. Contributor Grant.
112
+
113
+ Conditioned upon Your compliance with Section 3.1 below and
114
+ subject to third party intellectual property claims, each
115
+ Contributor hereby grants You a world-wide, royalty-free,
116
+ non-exclusive license:
117
+
118
+ (a) under intellectual property rights (other than
119
+ patent or trademark) Licensable by Contributor to
120
+ use, reproduce, modify, display, perform, sublicense
121
+ and distribute the Modifications created by such
122
+ Contributor (or portions thereof), either on an
123
+ unmodified basis, with other Modifications, as
124
+ Covered Software and/or as part of a Larger Work; and
125
+
126
+ (b) under Patent Claims infringed by the making,
127
+ using, or selling of Modifications made by that
128
+ Contributor either alone and/or in combination with
129
+ its Contributor Version (or portions of such
130
+ combination), to make, use, sell, offer for sale,
131
+ have made, and/or otherwise dispose of: (1)
132
+ Modifications made by that Contributor (or portions
133
+ thereof); and (2) the combination of Modifications
134
+ made by that Contributor with its Contributor Version
135
+ (or portions of such combination).
136
+
137
+ (c) The licenses granted in Sections 2.2(a) and
138
+ 2.2(b) are effective on the date Contributor first
139
+ distributes or otherwise makes the Modifications
140
+ available to a third party.
141
+
142
+ (d) Notwithstanding Section 2.2(b) above, no patent
143
+ license is granted: (1) for any code that Contributor
144
+ has deleted from the Contributor Version; (2) for
145
+ infringements caused by: (i) third party
146
+ modifications of Contributor Version, or (ii) the
147
+ combination of Modifications made by that Contributor
148
+ with other software (except as part of the
149
+ Contributor Version) or other devices; or (3) under
150
+ Patent Claims infringed by Covered Software in the
151
+ absence of Modifications made by that Contributor.
152
+
153
+ 3. Distribution Obligations.
154
+
155
+ 3.1. Availability of Source Code.
156
+
157
+ Any Covered Software that You distribute or otherwise make
158
+ available in Executable form must also be made available in
159
+ Source Code form and that Source Code form must be
160
+ distributed only under the terms of this License. You must
161
+ include a copy of this License with every copy of the
162
+ Source Code form of the Covered Software You distribute or
163
+ otherwise make available. You must inform recipients of any
164
+ such Covered Software in Executable form as to how they can
165
+ obtain such Covered Software in Source Code form in a
166
+ reasonable manner on or through a medium customarily used
167
+ for software exchange.
168
+
169
+ 3.2. Modifications.
170
+
171
+ The Modifications that You create or to which You
172
+ contribute are governed by the terms of this License. You
173
+ represent that You believe Your Modifications are Your
174
+ original creation(s) and/or You have sufficient rights to
175
+ grant the rights conveyed by this License.
176
+
177
+ 3.3. Required Notices.
178
+
179
+ You must include a notice in each of Your Modifications
180
+ that identifies You as the Contributor of the Modification.
181
+ You may not remove or alter any copyright, patent or
182
+ trademark notices contained within the Covered Software, or
183
+ any notices of licensing or any descriptive text giving
184
+ attribution to any Contributor or the Initial Developer.
185
+
186
+ 3.4. Application of Additional Terms.
187
+
188
+ You may not offer or impose any terms on any Covered
189
+ Software in Source Code form that alters or restricts the
190
+ applicable version of this License or the recipients'
191
+ rights hereunder. You may choose to offer, and to charge a
192
+ fee for, warranty, support, indemnity or liability
193
+ obligations to one or more recipients of Covered Software.
194
+ However, you may do so only on Your own behalf, and not on
195
+ behalf of the Initial Developer or any Contributor. You
196
+ must make it absolutely clear that any such warranty,
197
+ support, indemnity or liability obligation is offered by
198
+ You alone, and You hereby agree to indemnify the Initial
199
+ Developer and every Contributor for any liability incurred
200
+ by the Initial Developer or such Contributor as a result of
201
+ warranty, support, indemnity or liability terms You offer.
202
+
203
+ 3.5. Distribution of Executable Versions.
204
+
205
+ You may distribute the Executable form of the Covered
206
+ Software under the terms of this License or under the terms
207
+ of a license of Your choice, which may contain terms
208
+ different from this License, provided that You are in
209
+ compliance with the terms of this License and that the
210
+ license for the Executable form does not attempt to limit
211
+ or alter the recipient's rights in the Source Code form
212
+ from the rights set forth in this License. If You
213
+ distribute the Covered Software in Executable form under a
214
+ different license, You must make it absolutely clear that
215
+ any terms which differ from this License are offered by You
216
+ alone, not by the Initial Developer or Contributor. You
217
+ hereby agree to indemnify the Initial Developer and every
218
+ Contributor for any liability incurred by the Initial
219
+ Developer or such Contributor as a result of any such terms
220
+ You offer.
221
+
222
+ 3.6. Larger Works.
223
+
224
+ You may create a Larger Work by combining Covered Software
225
+ with other code not governed by the terms of this License
226
+ and distribute the Larger Work as a single product. In such
227
+ a case, You must make sure the requirements of this License
228
+ are fulfilled for the Covered Software.
229
+
230
+ 4. Versions of the License.
231
+
232
+ 4.1. New Versions.
233
+
234
+ Sun Microsystems, Inc. is the initial license steward and
235
+ may publish revised and/or new versions of this License
236
+ from time to time. Each version will be given a
237
+ distinguishing version number. Except as provided in
238
+ Section 4.3, no one other than the license steward has the
239
+ right to modify this License.
240
+
241
+ 4.2. Effect of New Versions.
242
+
243
+ You may always continue to use, distribute or otherwise
244
+ make the Covered Software available under the terms of the
245
+ version of the License under which You originally received
246
+ the Covered Software. If the Initial Developer includes a
247
+ notice in the Original Software prohibiting it from being
248
+ distributed or otherwise made available under any
249
+ subsequent version of the License, You must distribute and
250
+ make the Covered Software available under the terms of the
251
+ version of the License under which You originally received
252
+ the Covered Software. Otherwise, You may also choose to
253
+ use, distribute or otherwise make the Covered Software
254
+ available under the terms of any subsequent version of the
255
+ License published by the license steward.
256
+
257
+ 4.3. Modified Versions.
258
+
259
+ When You are an Initial Developer and You want to create a
260
+ new license for Your Original Software, You may create and
261
+ use a modified version of this License if You: (a) rename
262
+ the license and remove any references to the name of the
263
+ license steward (except to note that the license differs
264
+ from this License); and (b) otherwise make it clear that
265
+ the license contains terms which differ from this License.
266
+
267
+ 5. DISCLAIMER OF WARRANTY.
268
+
269
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
270
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
271
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
272
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
273
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
274
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
275
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
276
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
277
+ ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
278
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
279
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
280
+ DISCLAIMER.
281
+
282
+ 6. TERMINATION.
283
+
284
+ 6.1. This License and the rights granted hereunder will
285
+ terminate automatically if You fail to comply with terms
286
+ herein and fail to cure such breach within 30 days of
287
+ becoming aware of the breach. Provisions which, by their
288
+ nature, must remain in effect beyond the termination of
289
+ this License shall survive.
290
+
291
+ 6.2. If You assert a patent infringement claim (excluding
292
+ declaratory judgment actions) against Initial Developer or
293
+ a Contributor (the Initial Developer or Contributor against
294
+ whom You assert such claim is referred to as "Participant")
295
+ alleging that the Participant Software (meaning the
296
+ Contributor Version where the Participant is a Contributor
297
+ or the Original Software where the Participant is the
298
+ Initial Developer) directly or indirectly infringes any
299
+ patent, then any and all rights granted directly or
300
+ indirectly to You by such Participant, the Initial
301
+ Developer (if the Initial Developer is not the Participant)
302
+ and all Contributors under Sections 2.1 and/or 2.2 of this
303
+ License shall, upon 60 days notice from Participant
304
+ terminate prospectively and automatically at the expiration
305
+ of such 60 day notice period, unless if within such 60 day
306
+ period You withdraw Your claim with respect to the
307
+ Participant Software against such Participant either
308
+ unilaterally or pursuant to a written agreement with
309
+ Participant.
310
+
311
+ 6.3. In the event of termination under Sections 6.1 or 6.2
312
+ above, all end user licenses that have been validly granted
313
+ by You or any distributor hereunder prior to termination
314
+ (excluding licenses granted to You by any distributor)
315
+ shall survive termination.
316
+
317
+ 7. LIMITATION OF LIABILITY.
318
+
319
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
320
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
321
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
322
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
323
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
324
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
325
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
326
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
327
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
328
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
329
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
330
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
331
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
332
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
333
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
334
+ APPLY TO YOU.
335
+
336
+ 8. U.S. GOVERNMENT END USERS.
337
+
338
+ The Covered Software is a "commercial item," as that term is
339
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
340
+ computer software" (as that term is defined at 48 C.F.R. ¤
341
+ 252.227-7014(a)(1)) and "commercial computer software
342
+ documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
343
+ 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
344
+ through 227.7202-4 (June 1995), all U.S. Government End Users
345
+ acquire Covered Software with only those rights set forth herein.
346
+ This U.S. Government Rights clause is in lieu of, and supersedes,
347
+ any other FAR, DFAR, or other clause or provision that addresses
348
+ Government rights in computer software under this License.
349
+
350
+ 9. MISCELLANEOUS.
351
+
352
+ This License represents the complete agreement concerning subject
353
+ matter hereof. If any provision of this License is held to be
354
+ unenforceable, such provision shall be reformed only to the
355
+ extent necessary to make it enforceable. This License shall be
356
+ governed by the law of the jurisdiction specified in a notice
357
+ contained within the Original Software (except to the extent
358
+ applicable law, if any, provides otherwise), excluding such
359
+ jurisdiction's conflict-of-law provisions. Any litigation
360
+ relating to this License shall be subject to the jurisdiction of
361
+ the courts located in the jurisdiction and venue specified in a
362
+ notice contained within the Original Software, with the losing
363
+ party responsible for costs, including, without limitation, court
364
+ costs and reasonable attorneys' fees and expenses. The
365
+ application of the United Nations Convention on Contracts for the
366
+ International Sale of Goods is expressly excluded. Any law or
367
+ regulation which provides that the language of a contract shall
368
+ be construed against the drafter shall not apply to this License.
369
+ You agree that You alone are responsible for compliance with the
370
+ United States export administration regulations (and the export
371
+ control laws and regulation of any other countries) when You use,
372
+ distribute or otherwise make available any Covered Software.
373
+
374
+ 10. RESPONSIBILITY FOR CLAIMS.
375
+
376
+ As between Initial Developer and the Contributors, each party is
377
+ responsible for claims and damages arising, directly or
378
+ indirectly, out of its utilization of rights under this License
379
+ and You agree to work with Initial Developer and Contributors to
380
+ distribute such responsibility on an equitable basis. Nothing
381
+ herein is intended or shall be deemed to constitute any admission
382
+ of liability.
data/README.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ A ruby gem that reads a Rich Text Format (RTF) word processing file and outputs plain text.
2
+
3
+ == Usage
4
+
5
+ Convert rtf file to plain text
6
+
7
+ RtfFilter.to_txt('name_of_file.rtf')
8
+
9
+ Convert rtf file and format text (this will remove blank lines at top and bottom of document, multiple line breaks and justify text left)
10
+
11
+ RtfFilter.to_txt('name_of_file.rtf', :format_txt => true)
12
+
13
+ Convert rtf file to text file. Will create name_of_file.txt
14
+
15
+ RtfFilter.to_txt_file('name_of_file.rtf', :format_txt => true)
16
+
17
+ Specify directory text file should be written to
18
+
19
+ RtfFilter.to_txt_file('name_of_file.rtf', :destination_folder => 'folder_name', :format_txt => true)
20
+
21
+
22
+ Other options
23
+
24
+ :allow_tags => true #Does not supress output of angle bracketted tags e.g. <notes>, default is fase
25
+ :io_exception => true #Return IO exceptions instead of nil if there is a file / directory problem
26
+
27
+
28
+ == Installation
29
+
30
+ You need to have the rtf-filter C++ executable installed:
31
+
32
+ https://github.com/PS-Computer-Services-Ltd/rtf-filter
33
+
34
+
35
+ == Bug reports
36
+
37
+ If you discover a problem with rtf-filter, we would like to know about it.
38
+
39
+ Our Issues Tracker is available here:
40
+
41
+ https://pscomputer.lighthouseapp.com/projects/87573-rtf_filter-ruby-gem
42
+
43
+ == License
44
+
45
+ COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
46
+ Copyright PS Computer Services Ltd 2003-2011
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module RtfFilter
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rtf_filter.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "rtf_filter/version"
2
+
3
+ module RtfFilter
4
+ def self.to_txt(filename, options={})
5
+ allow_tags = options[:allow_tags] || false
6
+ begin
7
+ txt = ""
8
+ IO.popen("rtffilter --source '"+filename+"' --toStdOut"+self.allow_tags(allow_tags)).each_line do |l|
9
+ txt += l
10
+ end
11
+ self.format_txt(txt) if options[:format_txt]
12
+ raise IOError if txt == ""
13
+ return txt
14
+ rescue IOError => e
15
+ if options[:io_exception]
16
+ raise e
17
+ else
18
+ return nil
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.to_txt_file(filename, options={})
24
+ destination_folder = options[:destination_folder] || ""
25
+ allow_tags = options[:allow_tags] || false
26
+ begin
27
+ destination_folder += "/"unless destination_folder.empty?
28
+ destination = destination_folder + filename.sub(/.{3}$/,'txt')
29
+ txt = self.to_txt(filename, options)
30
+ File.open(destination, 'w') {|f| f.write(txt)}
31
+ rescue IOError => e
32
+ if options[:io_exception]
33
+ raise e
34
+ else
35
+ return nil
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.allow_tags(yes)
41
+ if yes
42
+ " --allowTags"
43
+ else
44
+ ""
45
+ end
46
+ end
47
+
48
+ def self.format_txt(txt)
49
+ txt.strip! #remove blank lines at begining and end
50
+ txt.gsub!(/(^|\n)[ \t\r]+/, "\\1") #delete leading whitespace (spaces/tabs) from beginning of each line
51
+ txt.gsub!(/\n{3,}/, '\n\n') #replace all occurrences of 3 or more line breaks with just two
52
+ return txt
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtf_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - PS Computer Services LTD
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-16 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Converts Rich Text Format (RTF) word processing files to plain text.
15
+ Uses the rtf-filter C++ executable
16
+ email:
17
+ - it@pscomputer.co.uk
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/rtf_filter.rb
23
+ - lib/rtf_filter/version.rb
24
+ - CDDL-LICENSE
25
+ - Rakefile
26
+ - README.rdoc
27
+ homepage: https://github.com/PS-Computer-Services-Ltd/rtf_filter
28
+ licenses:
29
+ - CDDL
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: rtf_filter
48
+ rubygems_version: 1.8.11
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Converts Rich Text Format (RTF) word processing files to plain text
52
+ test_files: []