rsl-stringex 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/lib/lucky_sneaks/string_extensions.rb +23 -2
- data/stringex.gemspec +2 -1
- data/test/string_extensions_test.rb +17 -1
- metadata +4 -3
data/Rakefile
CHANGED
@@ -9,6 +9,7 @@ begin
|
|
9
9
|
gem.authors = ["Russell Norris"]
|
10
10
|
gem.email = "rsl@luckysneaks.com"
|
11
11
|
gem.homepage = "http://github.com/rsl/stringex"
|
12
|
+
gem.rubyforge_project = "stringex"
|
12
13
|
gem.summary = "Some [hopefully] useful extensions to Ruby’s String class"
|
13
14
|
gem.description = "Some [hopefully] useful extensions to Ruby’s String class. Stringex is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class]."
|
14
15
|
gem.has_rdoc = true
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
module LuckySneaks
|
2
4
|
# These methods are all added on String class.
|
3
5
|
module StringExtensions
|
@@ -40,7 +42,12 @@ module LuckySneaks
|
|
40
42
|
# Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
|
41
43
|
# below to see which methods are run.
|
42
44
|
def remove_formatting
|
43
|
-
strip_html_tags.
|
45
|
+
strip_html_tags.
|
46
|
+
convert_german_umlauts.
|
47
|
+
convert_accented_entities.
|
48
|
+
convert_misc_entities.
|
49
|
+
convert_misc_characters.
|
50
|
+
to_ascii.collapse
|
44
51
|
end
|
45
52
|
|
46
53
|
# Removes HTML tags from text. This code is simplified from Tobias Luettke's regular expression
|
@@ -68,6 +75,20 @@ module LuckySneaks
|
|
68
75
|
gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/, '\1')
|
69
76
|
end
|
70
77
|
|
78
|
+
# Converts German Umlauts to their transliteration according to German conventions.
|
79
|
+
def convert_german_umlauts
|
80
|
+
map = {
|
81
|
+
"Ä" => "ae",
|
82
|
+
"Ö" => "oe",
|
83
|
+
"Ü" => "ue",
|
84
|
+
"ä" => "ae",
|
85
|
+
"ö" => "oe",
|
86
|
+
"ü" => "ue",
|
87
|
+
"ß" => "ss"
|
88
|
+
}
|
89
|
+
gsub(/#{map.keys.join('|')}/) { |match| map[match] }
|
90
|
+
end
|
91
|
+
|
71
92
|
# Converts HTML entities (taken from common Textile/RedCloth formattings) into plain text formats.
|
72
93
|
#
|
73
94
|
# Note: This isn't an attempt at complete conversion of HTML entities, just those most likely
|
@@ -174,4 +195,4 @@ module LuckySneaks
|
|
174
195
|
end
|
175
196
|
end
|
176
197
|
end
|
177
|
-
end
|
198
|
+
end
|
data/stringex.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{stringex}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Russell Norris"]
|
@@ -208,6 +208,7 @@ Gem::Specification.new do |s|
|
|
208
208
|
s.homepage = %q{http://github.com/rsl/stringex}
|
209
209
|
s.rdoc_options = ["--main", "README.rdoc", "--charset", "utf-8", "--line-numbers"]
|
210
210
|
s.require_paths = ["lib"]
|
211
|
+
s.rubyforge_project = %q{stringex}
|
211
212
|
s.rubygems_version = %q{1.3.2}
|
212
213
|
s.summary = %q{Some [hopefully] useful extensions to Ruby’s String class}
|
213
214
|
s.test_files = [
|
@@ -44,7 +44,9 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
44
44
|
"How to use attr_accessible and attr_protected" =>
|
45
45
|
"how-to-use-attr-accessible-and-attr-protected",
|
46
46
|
"I'm just making sure there's nothing wrong with things!" =>
|
47
|
-
"im-just-making-sure-theres-nothing-wrong-with-things"
|
47
|
+
"im-just-making-sure-theres-nothing-wrong-with-things",
|
48
|
+
"Umlaute hätten wir außerdem gern deutsch übersetzt." =>
|
49
|
+
"umlaute-haetten-wir-ausserdem-gern-deutsch-uebersetzt"
|
48
50
|
}.each do |html, plain|
|
49
51
|
assert_equal plain, html.to_url
|
50
52
|
end
|
@@ -89,6 +91,20 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
94
|
+
def test_convert_german_umlauts
|
95
|
+
{
|
96
|
+
"Ä" => "ae",
|
97
|
+
"Ö" => "oe",
|
98
|
+
"Ü" => "ue",
|
99
|
+
"ä" => "ae",
|
100
|
+
"ö" => "oe",
|
101
|
+
"ü" => "ue",
|
102
|
+
"ß" => "ss"
|
103
|
+
}.each do |entitied, plain|
|
104
|
+
assert_equal plain, entitied.convert_german_umlauts
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
92
108
|
def test_convert_misc_entities
|
93
109
|
{
|
94
110
|
"America™" => "America(tm)",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsl-stringex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Norris
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- stringex.gemspec
|
215
215
|
has_rdoc: true
|
216
216
|
homepage: http://github.com/rsl/stringex
|
217
|
+
licenses:
|
217
218
|
post_install_message:
|
218
219
|
rdoc_options:
|
219
220
|
- --main
|
@@ -237,8 +238,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
238
|
version:
|
238
239
|
requirements: []
|
239
240
|
|
240
|
-
rubyforge_project:
|
241
|
-
rubygems_version: 1.
|
241
|
+
rubyforge_project: stringex
|
242
|
+
rubygems_version: 1.3.5
|
242
243
|
signing_key:
|
243
244
|
specification_version: 3
|
244
245
|
summary: "Some [hopefully] useful extensions to Ruby\xE2\x80\x99s String class"
|