Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/rsl/stringex
Browse files Browse the repository at this point in the history
  • Loading branch information
oleriesenberg committed Aug 19, 2009
2 parents 0294d22 + c75d9e0 commit e538f2c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.0.0
1.0.1
21 changes: 20 additions & 1 deletion lib/lucky_sneaks/string_extensions.rb
Expand Up @@ -42,7 +42,12 @@ def to_url
# Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
# below to see which methods are run.
def remove_formatting
strip_html_tags.convert_accented_entities.convert_misc_entities.convert_misc_characters.to_ascii.collapse
strip_html_tags.
convert_german_umlauts.
convert_accented_entities.
convert_misc_entities.
convert_misc_characters.
to_ascii.collapse
end

# Removes HTML tags from text. This code is simplified from Tobias Luettke's regular expression
Expand Down Expand Up @@ -70,6 +75,20 @@ def convert_accented_entities
gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/, '\1')
end

# Converts German Umlauts to their transliteration according to German conventions.
def convert_german_umlauts
map = {
"Ä" => "ae",
"Ö" => "oe",
"Ü" => "ue",
"ä" => "ae",
"ö" => "oe",
"ü" => "ue",
"ß" => "ss"
}
gsub(/#{map.keys.join('|')}/) { |match| map[match] }
end

# Converts HTML entities (taken from common Textile/RedCloth formattings) into plain text formats.
#
# Note: This isn't an attempt at complete conversion of HTML entities, just those most likely
Expand Down
2 changes: 1 addition & 1 deletion stringex.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{stringex}
s.version = "1.0.0"
s.version = "1.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Russell Norris"]
Expand Down
18 changes: 17 additions & 1 deletion test/string_extensions_test.rb
Expand Up @@ -44,7 +44,9 @@ def test_to_url
"How to use attr_accessible and attr_protected" =>
"how-to-use-attr-accessible-and-attr-protected",
"I'm just making sure there's nothing wrong with things!" =>
"im-just-making-sure-theres-nothing-wrong-with-things"
"im-just-making-sure-theres-nothing-wrong-with-things",
"Umlaute hätten wir außerdem gern deutsch übersetzt." =>
"umlaute-haetten-wir-ausserdem-gern-deutsch-uebersetzt"
}.each do |html, plain|
assert_equal plain, html.to_url
end
Expand Down Expand Up @@ -89,6 +91,20 @@ def test_convert_accented_entities
end
end

def test_convert_german_umlauts
{
"Ä" => "ae",
"Ö" => "oe",
"Ü" => "ue",
"ä" => "ae",
"ö" => "oe",
"ü" => "ue",
"ß" => "ss"
}.each do |entitied, plain|
assert_equal plain, entitied.convert_german_umlauts
end
end

def test_convert_misc_entities
{
"America™" => "America(tm)",
Expand Down

0 comments on commit e538f2c

Please sign in to comment.