Permalink
Browse files

fixing a bug in this with ruby 1.8.7. I guess people use this library?

  • Loading branch information...
1 parent d5aa4a5 commit 067b0f5f93e216c5bc5bde51fdd7f711549963ff @tenderlove committed Oct 6, 2008
Showing with 31 additions and 43 deletions.
  1. +9 −0 CHANGELOG.txt → History.txt
  2. +2 −10 README.txt
  3. +3 −14 Rakefile
  4. +14 −11 lib/namecase.rb
  5. +0 −3 lib/version.rb
  6. +3 −5 test/test_namecase.rb
@@ -1,5 +1,14 @@
= NameCase CHANGELOG
+== 1.1.0
+
+* New Features:
+ * NameCase() function returns a namecased string
+ * NameCase.nc methind returns a namecased string
+
+* Bug Fixes:
+ * Not using chars method, was breaking 1.8.7
+
== 1.0.2
* Updating NameCase to work with the new Edge Rails ActiveSupport::Multibye
View
@@ -2,24 +2,16 @@
http://namecase.rubyforge.org/
-Version 1.0.2 - 2006/10/24
-
== DESCRIPTION
NameCase is a Ruby implementation of Lingua::EN::NameCase, a library for
converting strings to be properly cased. This is good for converting
denormalized data to human friendly data.
-Original version by Mark Summerfield <http://search.cpan.org/~summer/>
-Ruby port by Aaron Patterson <aaronp@rubyforge.org>
-
* Example Usage
-NameCase is a subclass of Ruby's +String+, and can be used similarly:
-
- string = NameCase.new( string )
- puts string.nc
- puts string.nc!
+ NameCase("RON BURGUNDY") # => Ron Burgundy
+ NameCase("MCDONALDS") # => McDonalds
* Acknowledgements
View
@@ -1,18 +1,7 @@
require 'rubygems'
require 'hoe'
+require './lib/namecase.rb'
-PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
-PKG_NAME = 'namecase'
-PKG_VERSION = '1.0.2' + PKG_BUILD
-ENV["VERSION"] = PKG_VERSION
-
-Hoe.new(PKG_NAME, PKG_VERSION) do |p|
- p.rubyforge_name = PKG_NAME
- p.author = 'Aaron Patterson'
- p.email = 'aaronp@rubyforge.org'
- p.summary = "NameCase is a Ruby implementation of Lingua::EN::NameCase, a library for converting strings to be properly cased."
- p.description = p.paragraphs_of('README.txt', 4).join("\n\n")
- p.url = p.paragraphs_of('README.txt', 1).first.strip
- p.changes = p.paragraphs_of('CHANGELOG.txt', 0..2).join("\n\n")
- p.spec_extras = { :test_files => Dir[*p.test_globs] }
+Hoe.new('namecase', NameCase::VERSION) do |p|
+ p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
end
View
@@ -1,18 +1,17 @@
-require 'version'
-
class NameCase < String
+ VERSION = '1.1.0'
+
+ class << self
+ def nc string
+ new(string).nc
+ end
+ end
# Returns a new +String+ with the contents properly namecased
def nc
- 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
+ localstring = downcase
+ localstring.gsub!(/\b\w/) { |first| first.upcase }
+ localstring.gsub!(/\'\w\b/) { |c| c.downcase } # Lowercase 's
if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/
localstring.gsub!(/\b(Ma?c)([A-Za-z]+)/) { |match| $1 + $2.capitalize }
@@ -59,3 +58,7 @@ def nc!
self.gsub!(self, self.nc)
end
end
+
+def NameCase string
+ NameCase.new(string).nc
+end
View
@@ -1,3 +0,0 @@
-class NameCase < String
- Version = '1.0.2'
-end
View
@@ -33,6 +33,8 @@ def test_namecase
@proper_names.each do |name|
nc_name = NameCase.new(name)
assert_equal(name, nc_name.downcase.nc)
+ assert_equal(name, NameCase.nc(name))
+ assert_equal(name, NameCase(name))
end
end
@@ -44,14 +46,10 @@ def test_namecase_modify
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 }
+ assert_equal(proper_cased, nc_name.downcase.nc)
end
end

0 comments on commit 067b0f5

Please sign in to comment.