Normalize fullwidth (zenkaku) and halfwidth (hankaku) characters
Ruby
Latest commit 4f6f968 May 15, 2014 @labocho Merge pull request #1 from ma2gedev/patch-1
fix typo
Permalink
Failed to load latest commit information.
bin
lib
spec add active_record integration Apr 4, 2014
.cleancode
.document Initial commit to charwidth_normalization. Feb 7, 2012
.gitignore Remove dependency on jeweler Dec 20, 2013
.rspec Initial commit to charwidth_normalization. Feb 7, 2012
Gemfile
Gemfile.lock add active_record integration Apr 4, 2014
LICENSE.txt
README.md fix typo May 15, 2014
Rakefile Remove dependency on jeweler Dec 20, 2013
charwidth.gemspec add active_record integration Apr 4, 2014

README.md

charwidth

Normalize Unicode fullwidth / halfwidth (zenkaku / hankaku) characters.

Installation

Add this line to your application's Gemfile:

gem 'charwidth'

And then execute:

$ bundle

Or install it yourself as:

$ gem install charwidth

Usage

require "charwidth"
Charwidth.normalize("Hello, World!") # => "Hello, World!"
Charwidth.normalize!("Hello, World!") # destructive
Charwidth.normalize("「ハローワールド」") # => "「ハローワールド」"

Or extend String class.

require "charwidth/string"
"Hello, World!".normalize_charwidth # => "Hello, World!"
"Hello, World!".normalize_charwidth! # => destructive
"「ハローワールド」".normalize_charwidth # => "「ハローワールド」"

ActiveRecord integration

Write require "charwidth/active_record" to normalize all values of ActiveRecord attributes.

require "charwidth/active_record"

class Article < ActiveRecord::Base
end

a = Article.new(title: "Hello, World!")
a.title # => "Hello, World!"

CLI

# Call charwidth command with arguments
$ charwidth "Hello, World!"
Hello, World!
# Or as STDIN
$ echo "Hello, World!" | charwidth
Hello, World!

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request