text 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/lib/text.rb +24 -1
- data/lib/text/double_metaphone.rb +2 -1
- data/lib/text/figlet/font.rb +3 -1
- data/lib/text/figlet/smusher.rb +1 -0
- data/lib/text/figlet/typesetter.rb +1 -0
- data/lib/text/levenshtein.rb +4 -1
- data/lib/text/version.rb +1 -1
- data/test/data/double_metaphone.csv +1218 -1218
- data/test/test_double_metaphone.rb +3 -10
- data/test/test_figlet.rb +11 -10
- data/test/test_levenshtein.rb +19 -7
- metadata +2 -2
@@ -1,20 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'preamble')
|
2
2
|
|
3
|
-
|
4
|
-
require 'rubygems' rescue nil
|
5
|
-
require 'fastercsv'
|
6
|
-
METHOD = [ FasterCSV, :foreach, { :col_sep => ', ' } ]
|
7
|
-
rescue LoadError
|
8
|
-
require 'csv'
|
9
|
-
METHOD = [ CSV, :open, 'r', ', ' ]
|
10
|
-
end
|
3
|
+
require 'csv'
|
11
4
|
|
12
5
|
class DoubleMetaphoneTest < Test::Unit::TestCase
|
13
6
|
|
14
7
|
def test_cases
|
15
|
-
|
8
|
+
CSV.open(File.rel('data', 'double_metaphone.csv'), 'r').to_a.each do |row|
|
16
9
|
primary, secondary = Text::Metaphone.double_metaphone(row[0])
|
17
|
-
|
10
|
+
|
18
11
|
assert_equal row[1], primary
|
19
12
|
assert_equal row[2], secondary.nil?? primary : secondary
|
20
13
|
end
|
data/test/test_figlet.rb
CHANGED
@@ -2,16 +2,17 @@ require File.join(File.dirname(__FILE__), 'preamble')
|
|
2
2
|
|
3
3
|
class FigletTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
if !Text.is_19?
|
6
|
+
def test_hello_world
|
7
|
+
font = Text::Figlet::Font.new(File.rel('data', 'big.flf'))
|
8
|
+
figlet = Text::Figlet::Typesetter.new(font)
|
9
|
+
assert_equal File.read(File.rel('data', 'big.txt')), figlet['Hello World']
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def test_no_smushing
|
13
|
+
font = Text::Figlet::Font.new(File.rel('data', 'chunky.flf'))
|
14
|
+
figlet = Text::Figlet::Typesetter.new(font, :smush => false)
|
15
|
+
assert_equal File.read(File.rel('data', 'chunky.txt')), figlet['Chunky Bacon']
|
16
|
+
end
|
15
17
|
end
|
16
|
-
|
17
18
|
end
|
data/test/test_levenshtein.rb
CHANGED
@@ -41,16 +41,28 @@ class LevenshteinTest < Test::Unit::TestCase
|
|
41
41
|
|
42
42
|
def assert_set(name)
|
43
43
|
TEST_CASES[name].each do |s, t, x|
|
44
|
+
if defined?(Encoding) && Encoding.default_internal # Change the encoding if in 1.9
|
45
|
+
t.force_encoding(Encoding.default_internal)
|
46
|
+
s.force_encoding(Encoding.default_internal)
|
47
|
+
end
|
48
|
+
|
44
49
|
assert_equal x, distance(s, t)
|
45
50
|
assert_equal x, distance(t, s)
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
def with_encoding(kcode, encoding)
|
55
|
+
if Text.is_19?
|
56
|
+
old_encoding = Encoding.default_internal
|
57
|
+
Encoding.default_internal = encoding
|
58
|
+
yield
|
59
|
+
Encoding.default_internal = old_encoding
|
60
|
+
else # 1.8 backwards compat
|
61
|
+
old_kcode = $KCODE
|
62
|
+
$KCODE = kcode
|
63
|
+
yield
|
64
|
+
$KCODE = old_kcode
|
65
|
+
end
|
54
66
|
end
|
55
67
|
|
56
68
|
def test_easy_cases
|
@@ -66,13 +78,13 @@ class LevenshteinTest < Test::Unit::TestCase
|
|
66
78
|
end
|
67
79
|
|
68
80
|
def test_utf8_cases
|
69
|
-
|
81
|
+
with_encoding('U', 'UTF-8') do
|
70
82
|
assert_set(:utf8)
|
71
83
|
end
|
72
84
|
end
|
73
85
|
|
74
86
|
def test_iso_8859_1_cases
|
75
|
-
|
87
|
+
with_encoding('NONE', 'ISO-8859-1') do
|
76
88
|
assert_set(:iso_8859_1)
|
77
89
|
end
|
78
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Battley
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date:
|
14
|
+
date: 2010-02-02 00:00:00 +00:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|