xtotxt 0.4 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/xtotxt.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'yaml'
2
2
 
3
+ class XtotxtError < StandardError; end
4
+
3
5
  class Xtotxt
6
+ VERSION = 0.5
7
+ SUPPORTED_EXTENSIONS = %w{pdf doc docx odt rtf html}
8
+
4
9
  @@config_file_name = "xtotxt.yml"
5
10
  @@dirs_to_check = %w{. ~ /etc}
6
11
  @@ext = nil
@@ -15,6 +20,7 @@ class Xtotxt
15
20
  end
16
21
  end
17
22
  end
23
+ @@ext = @ext_default
18
24
  end
19
25
 
20
26
  def convert(input_file_name)
@@ -22,7 +28,7 @@ class Xtotxt
22
28
 
23
29
  ext = path_list.pop
24
30
 
25
- raise("not a supported document extension: #{ext}") unless %w{pdf doc docx odt rtf html}.member?(ext)
31
+ raise XtotxtError.new("not a supported document extension: #{ext}") unless SUPPORTED_EXTENSIONS.member?(ext)
26
32
 
27
33
  output_file = (path_list << "txt").join(".")
28
34
 
@@ -40,7 +46,7 @@ class Xtotxt
40
46
  when "html":
41
47
  "#{@ext[:html]} -o #{output_file} #{input_file_name}"
42
48
  else
43
- raise "have no way to convert #{ext} yet"
49
+ raise XtotxtError.new("have no way to convert #{ext} yet")
44
50
  end
45
51
 
46
52
  #puts "executing: #{command_line}"
@@ -49,7 +55,7 @@ class Xtotxt
49
55
  text = if $? == 0
50
56
  File.read(output_file)
51
57
  else
52
- raise "Failed to convert #{input_file_name}. Exit status: #{$?.exitstatus}. Output: #{command_output}"
58
+ raise XtotxtError.new("Failed to convert #{input_file_name}. Exit status: #{$?.exitstatus}. Output: #{command_output}")
53
59
  end
54
60
 
55
61
  case ext
data/spec/xtotxt.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  :pdf: "/opt/local/bin/xpdf-pdftotext"
2
2
  :doc: "/opt/local/bin/antiword"
3
3
  :docx: "/usr/local/bin/docx2txt.pl"
4
- :odt: "/usr/local/bin/odt2txt"
4
+ :odt: "/opt/local/bin/odt2txt"
5
5
  :rtf: "/opt/local/bin/unrtf -P /opt/local/lib/unrtf"
6
6
  :html: "/opt/local/bin/html2text"
data/spec/xtotxt_spec.rb CHANGED
@@ -4,6 +4,7 @@ require 'xtotxt'
4
4
  describe Xtotxt do
5
5
  before(:all) do
6
6
  @input_prefix = "#{Pathname.new(__FILE__).dirname}/fixtures/test"
7
+ @text = "three pigheaded piglets had a plan"
7
8
  end
8
9
 
9
10
  before do
@@ -36,37 +37,37 @@ describe Xtotxt do
36
37
  it "converts a pdf document correctly" do
37
38
  text = @x.convert("#{@input_prefix}.pdf")
38
39
 
39
- text.should == "three pigheaded piglets had a plan\n\n\f"
40
+ text.strip.should == @text
40
41
  end
41
42
 
42
43
  it "converts a doc document correctly" do
43
44
  text = @x.convert("#{@input_prefix}.doc")
44
45
 
45
- text.should == "\nthree pigheaded piglets had a plan\n\n"
46
+ text.strip.should == @text
46
47
  end
47
48
 
48
49
  it "converts a docx document correctly" do
49
50
  text = @x.convert("#{@input_prefix}.docx")
50
51
 
51
- text.should == "three pigheaded piglets had a plan\n\n"
52
+ text.strip.should == @text
52
53
  end
53
54
 
54
55
  it "converts an odt document correctly" do
55
56
  text = @x.convert("#{@input_prefix}.odt")
56
57
 
57
- text.should == "\nthree pigheaded piglets had a plan\n\n"
58
+ text.strip.should == @text
58
59
  end
59
60
 
60
61
  it "converts an rtf document correctly" do
61
62
  text = @x.convert("#{@input_prefix}.rtf")
62
63
 
63
- text.should == "three pigheaded piglets had a plan\n"
64
+ text.strip.should == @text
64
65
  end
65
66
 
66
67
  it "converts an html document correctly" do
67
68
  text = @x.convert("#{@input_prefix}.html")
68
69
 
69
- text.should == "three pigheaded piglets had a plan\n"
70
+ text.strip.should == @text
70
71
  end
71
72
 
72
73
 
data/xtotxt.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "xtotxt/version"
3
+ require "lib/xtotxt"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "xtotxt"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xtotxt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
8
+ - 5
9
+ version: "0.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexy Khrabrov
@@ -14,7 +14,8 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-23 00:00:00 Z
17
+ date: 2011-09-30 00:00:00 -07:00
18
+ default_executable:
18
19
  dependencies: []
19
20
 
20
21
  description: A simple wrapper calling, for each supported input format, a given command-line tool
@@ -41,12 +42,10 @@ files:
41
42
  - spec/xtotxt.yml
42
43
  - spec/xtotxt_spec.rb
43
44
  - xtotxt.gemspec
44
- - xtotxt/version.rb
45
+ has_rdoc: true
45
46
  homepage: http://www.topprospect.com
46
47
  licenses: []
47
48
 
48
- metadata: {}
49
-
50
49
  post_install_message:
51
50
  rdoc_options: []
52
51
 
@@ -73,9 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
72
  requirements: []
74
73
 
75
74
  rubyforge_project: xtotxt
76
- rubygems_version: 1.8.10
75
+ rubygems_version: 1.6.2
77
76
  signing_key:
78
- specification_version: 4
77
+ specification_version: 3
79
78
  summary: Convert pdf, doc and docx to plain text
80
79
  test_files:
81
80
  - spec/fixtures/test.doc
data/xtotxt/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Xtotxt
2
- VERSION = 0.4
3
- end