xtotxt 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/xtotxt.rb CHANGED
@@ -1,4 +1,21 @@
1
+ require 'yaml'
2
+
1
3
  class Xtotxt
4
+ @@config_file_name = "xtotxt.yml"
5
+ @@dirs_to_check = %w{. ~ /etc}
6
+ @@ext = nil
7
+
8
+ def self.read_config
9
+ @@dirs_to_check.each do |dir|
10
+ ["","."].each do |prefix|
11
+ file_name = "#{dir}/#{prefix}#{@@config_file_name}"
12
+ if File.exists?(file_name)
13
+ @@ext = YAML.load_file(file_name)
14
+ return
15
+ end
16
+ end
17
+ end
18
+ end
2
19
 
3
20
  def convert(input_file_name)
4
21
  path_list = input_file_name.split(".")
@@ -29,8 +46,19 @@ class Xtotxt
29
46
  text
30
47
  end
31
48
 
32
- def initialize(ext)
33
- @ext = ext || @@ext
49
+ def initialize(ext=nil)
50
+ @ext =
51
+ case
52
+ when ext
53
+ ext
54
+ when @@ext
55
+ @@ext
56
+ else
57
+ Xtotxt.read_config
58
+ @@ext
59
+ end
60
+
61
+ puts "@ext: #{@ext}, @@ext: #{@@ext}"
34
62
  end
35
63
 
36
64
  end
data/spec/xtotxt.yml ADDED
@@ -0,0 +1,3 @@
1
+ :pdf: "/opt/local/bin/xpdf-pdftotext"
2
+ :doc: "/opt/local/bin/antiword"
3
+ :docx: "/usr/local/bin/docx2txt.pl"
data/spec/xtotxt_spec.rb CHANGED
@@ -2,12 +2,9 @@ require 'spec_helper'
2
2
  require 'xtotxt'
3
3
 
4
4
  describe Xtotxt do
5
- before do
6
- @ext = { :pdf => "/opt/local/bin/xpdf-pdftotext",
7
- :doc => "/opt/local/bin/antiword",
8
- :docx => "/usr/local/bin/docx2txt.pl" }
9
5
 
10
- @x = Xtotxt.new(@ext)
6
+ before do
7
+ @x = Xtotxt.new
11
8
  @input_prefix = "fixtures/test"
12
9
  end
13
10
 
data/xtotxt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xtotxt
2
- VERSION = 0.2
2
+ VERSION = 0.3
3
3
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexy Khrabrov
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-20 00:00:00 Z
17
+ date: 2011-09-21 00:00:00 Z
18
18
  dependencies: []
19
19
 
20
20
  description: A simple wrapper calling, for each supported input format, a given command-line tool
@@ -34,6 +34,7 @@ files:
34
34
  - spec/fixtures/test.docx
35
35
  - spec/fixtures/test.pdf
36
36
  - spec/spec_helper.rb
37
+ - spec/xtotxt.yml
37
38
  - spec/xtotxt_spec.rb
38
39
  - xtotxt.gemspec
39
40
  - xtotxt/version.rb
@@ -77,4 +78,5 @@ test_files:
77
78
  - spec/fixtures/test.docx
78
79
  - spec/fixtures/test.pdf
79
80
  - spec/spec_helper.rb
81
+ - spec/xtotxt.yml
80
82
  - spec/xtotxt_spec.rb