Skip to content

Commit

Permalink
adding patch to support EdgeRails multibyte class. thanks Dan Cubb
Browse files Browse the repository at this point in the history
git-svn-id: svn://rubyforge.org/var/svn/namecase/trunk@39 917ac306-ed13-0410-8fcf-ecc17ec2e4de
  • Loading branch information
aaronp committed Oct 28, 2006
1 parent 4f5a67f commit 0f0395a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
@@ -1,4 +1,11 @@
*1.0.0*
= NameCase CHANGELOG

== 1.0.2

* Updating NameCase to work with the new Edge Rails ActiveSupport::Multibye
class. Thanks Dan Kubb (dan.kubb@autopilotmarketing.com)

== 1.0.0

* Initial release

5 changes: 2 additions & 3 deletions README
@@ -1,6 +1,6 @@
== NameCase

Version 1.0.0 - 2005/11/2
Version 1.0.2 - 2006/10/24

Original version by Mark Summerfield <http://search.cpan.org/~summer/>
Ruby port by Aaron Patterson <aaronp@rubyforge.org>
Expand Down Expand Up @@ -31,9 +31,8 @@ Copyright (c) Mark Summerfield 1998-2002.
All Rights Reserved

Ruby Version:
Copyright (c) Aaron Patterson 2005
Copyright (c) Aaron Patterson 2006

* License

NameCase is distributed under the GPL license. Please see the LICENSE file.

2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ end

PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME = 'namecase'
PKG_VERSION = '1.0.1' + PKG_BUILD
PKG_VERSION = '1.0.2' + PKG_BUILD
PKG_FILES = FileList["{doc,lib,test}/**/*"].exclude("rdoc").to_a

spec = Gem::Specification.new do |s|
Expand Down
12 changes: 9 additions & 3 deletions lib/namecase.rb
Expand Up @@ -4,9 +4,15 @@ class NameCase < String

# Returns a new +String+ with the contents properly namecased
def nc
localstring = self.downcase
localstring.gsub!(/\b\w/) { |first| first.upcase }
localstring.gsub!("\'\w\b") { |c| c.downcase } # Lowercase 's
if respond_to?(:chars)
localstring = chars.downcase.to_s
localstring.gsub!(/\b\w/) { |first| first.chars.upcase }
localstring.gsub!(/\'\w\b/) { |c| c.chars.downcase } # Lowercase 's
else
localstring = downcase
localstring.gsub!(/\b\w/) { |first| first.upcase }
localstring.gsub!(/\'\w\b/) { |c| c.downcase } # Lowercase 's
end

if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/
localstring.gsub!(/\b(Ma?c)([A-Za-z]+)/) { |match| $1 + $2.capitalize }
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
@@ -1,5 +1,5 @@
# DO NOT EDIT
# This file is auto-generated by build scripts
class NameCase < String
Version = '1.0.1'
Version = '1.0.2'
end
18 changes: 15 additions & 3 deletions test/test_namecase.rb
Expand Up @@ -9,10 +9,10 @@ def setup
@proper_names = [
"Keith", "Leigh-Williams", "McCarthy",
"O'Callaghan", "St. John", "von Streit",
"van Dyke", "Van", "ap Llwyd Dafydd",
"al Fahd", "Al",
"van Dyke", "Van", "ap Llwyd Dafydd",
"al Fahd", "Al",
"el Grecco",
"ben Gurion", "Ben",
"ben Gurion", "Ben",
"da Vinci",
"di Caprio", "du Pont", "de Legate",
"del Crond", "der Sind", "van der Post",
Expand Down Expand Up @@ -42,4 +42,16 @@ def test_namecase_modify
assert_equal(name, nc_name.downcase.nc!)
end
end

def test_namecase_multibyte
String.class_eval { define_method(:chars) { self } }

$KCODE = 'u'

proper_cased = 'Iñtërnâtiônàlizætiøn'
nc_name = NameCase.new(proper_cased)
assert_equal(proper_cased, nc_name.downcase.nc!)

String.class_eval { undef_method :chars }
end
end

0 comments on commit 0f0395a

Please sign in to comment.