0.0
No commit activity in last 3 years
No release in over 3 years
Normalize_jp is integreated to ActiveRecord
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 11.0
~> 10.0
~> 3.0
~> 1.3, < 1.4

Runtime

 Project Readme

NormalizerJp

This gem a provites a simple and flexible way to normalize attributes of Ruby Object. NormalizerJP includes a word JP(stands for Japanese), but this gem is useful for the other(not Japanese) because you can use your customized Normalizer.

Installation

Add this line to your application's Gemfile:

gem 'normalizer_jp'

Or install it yourself as:

$ gem install normalizer_jp

Getting Started

Start off by generating normalizer:

bin/rails g normalizer Strip

this should give you a file in:

app/normalizers/strip_normalizer.rb

Check out this file for some hints on how you can customize your normlizer. It should look something like this:

class StripNormalizer < NormalizerJp::Normalizers::Base
  class << self
    # Normalizer class's responsibility is implimentaion of call method as class method
    def call(attribute_value)
      # Here's normalizer space
    end
  end
end

Usage

ActiveRecord

you can use normalizers of this gem.

class User < ActiveRecord
  include NormalizerJp::Normalizers

  mount_normalizer :name_kana, HiraganaNormalizer
end

normlizer works as following:

user = User.new
user.name_kana = 'イトウアサコ'
user.name_kana #=> 'いとうあさこ'

you can use custom normalizers. custom normalizers's responsibility is implementation of call method as class method. It's super cool.

# app/normalizers/upcase_normalizer.rb
class UpcaseNormalizer < NormalizerJp::Normalizers::Base
  class << self
    def call(attribute_value)
      attribute_value.to_s.upcase
    end
  end
end

# app/models/blog.rb
class Blog < ActiveRecord
  mount_normalizer :title, UpcaseNormalizer
end

custom normalizer works as following:

blog = Blog.new
blog.title = 'awesome title'
blog.title #=> 'AWESOME TITLE'

Plain Old Ruby Object

this gem dose not depends active_record, which mean we use this gem in Plain Old Ruby Object.

Versioning

This project uses Semantic Versioning for release numbering.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/koukikitamura/normalize_jp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the NormalizerJp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.