Hoodow-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/lib/lucky_sneaks/string_extensions.rb +20 -1
- data/stringex.gemspec +1 -1
- data/test/string_extensions_test.rb +17 -1
- metadata +1 -1
@@ -42,7 +42,12 @@ module LuckySneaks
|
|
42
42
|
# Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
|
43
43
|
# below to see which methods are run.
|
44
44
|
def remove_formatting
|
45
|
-
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
|
46
51
|
end
|
47
52
|
|
48
53
|
# Removes HTML tags from text. This code is simplified from Tobias Luettke's regular expression
|
@@ -70,6 +75,20 @@ module LuckySneaks
|
|
70
75
|
gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/, '\1')
|
71
76
|
end
|
72
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
|
+
|
73
92
|
# Converts HTML entities (taken from common Textile/RedCloth formattings) into plain text formats.
|
74
93
|
#
|
75
94
|
# Note: This isn't an attempt at complete conversion of HTML entities, just those most likely
|
data/stringex.gemspec
CHANGED
@@ -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)",
|