stringex 1.0.0 → 1.0.1
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/lucky_sneaks/string_extensions.rb +23 -2
- data/stringex.gemspec +3 -4
- data/test/string_extensions_test.rb +17 -1
- metadata +3 -3
@@ -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,11 +2,11 @@
|
|
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"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-19}
|
10
10
|
s.description = %q{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].}
|
11
11
|
s.email = %q{rsl@luckysneaks.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -204,12 +204,11 @@ Gem::Specification.new do |s|
|
|
204
204
|
"lib/stringex.rb",
|
205
205
|
"stringex.gemspec"
|
206
206
|
]
|
207
|
-
s.has_rdoc = true
|
208
207
|
s.homepage = %q{http://github.com/rsl/stringex}
|
209
208
|
s.rdoc_options = ["--main", "README.rdoc", "--charset", "utf-8", "--line-numbers"]
|
210
209
|
s.require_paths = ["lib"]
|
211
210
|
s.rubyforge_project = %q{stringex}
|
212
|
-
s.rubygems_version = %q{1.3.
|
211
|
+
s.rubygems_version = %q{1.3.5}
|
213
212
|
s.summary = %q{Some [hopefully] useful extensions to Ruby’s String class}
|
214
213
|
s.test_files = [
|
215
214
|
"test/acts_as_url_test.rb",
|
@@ -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: 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
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-19 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
240
|
requirements: []
|
241
241
|
|
242
242
|
rubyforge_project: stringex
|
243
|
-
rubygems_version: 1.3.
|
243
|
+
rubygems_version: 1.3.5
|
244
244
|
signing_key:
|
245
245
|
specification_version: 3
|
246
246
|
summary: "Some [hopefully] useful extensions to Ruby\xE2\x80\x99s String class"
|