normalizer_jp 0.4.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +45 -10
- data/lib/normalizer_jp/normalizers/hankaku_normalizer.rb +1 -1
- data/lib/normalizer_jp/normalizers/hiragana_normalizer.rb +1 -1
- data/lib/normalizer_jp/normalizers/katakana_normalizer.rb +1 -1
- data/lib/normalizer_jp/normalizers.rb +11 -4
- data/lib/normalizer_jp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417d64efbb124b0e5372e05baeeeef03adacb7813ac02ed4a7a457ddcd903e9c
|
4
|
+
data.tar.gz: 30e5c9a1dd10f7836e5f28da2d9efde85165071ee0ea29eb78f0dd8ed4afef08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9610ae79fe74310a87159c992f9250a4cdb528a78513b6789ef6eb52ec44aeca34a616fd84d23e573e3d61cb1f84fa190966a255437f1ee6bf00b6392d993f6
|
7
|
+
data.tar.gz: f6faec9b08413e0ee6c1d678f9a76d0fa3c6b351e792f896a08138097725d5585a35befecb50c8d9d80468fca1e4ed0e08b7d38c491cfb95ed5738891a2b9ef0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# NormalizerJp
|
2
2
|
|
3
|
-
|
3
|
+
This gem a provites a simple and flexible way to normalize attributes of
|
4
|
+
Ruby Object. NormalizerJP includes a word JP(stands for Japanese), but this gem
|
5
|
+
is useful for the other(not Japanese) because you can user custom Normalizer.
|
4
6
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -12,23 +13,57 @@ Add this line to your application's Gemfile:
|
|
12
13
|
gem 'normalizer_jp'
|
13
14
|
```
|
14
15
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
16
|
Or install it yourself as:
|
20
17
|
|
21
18
|
$ gem install normalizer_jp
|
22
19
|
|
23
20
|
## Usage
|
24
21
|
|
25
|
-
|
22
|
+
### ActiveRecord
|
23
|
+
you can use normalizers of this gem.
|
24
|
+
```ruby
|
25
|
+
class User < ActiveRecord
|
26
|
+
include NormalizerJp::Normalizers
|
26
27
|
|
27
|
-
|
28
|
+
mount_normalizer :name_kana, HiraganaNormalizer
|
29
|
+
end
|
30
|
+
```
|
31
|
+
normlizer works as following:
|
32
|
+
```ruby
|
33
|
+
user = User.new
|
34
|
+
user.name_kana = 'イトウアサコ'
|
35
|
+
user.name_kana #=> 'いとうあさこ'
|
36
|
+
```
|
28
37
|
|
29
|
-
|
38
|
+
you can use custom normalizer. customer normalizer's responsibility is implementation of call method as class method. It's super cool.
|
39
|
+
```ruby
|
40
|
+
# app/normalizers/upcase_normalizer.rb
|
41
|
+
class UpcaseNormalizer < NormalizerJp::Normalizers::Base
|
42
|
+
class << self
|
43
|
+
def call(attribute_value)
|
44
|
+
attribute_value.to_s.upcase
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# app/models/blog.rb
|
50
|
+
class Blog < ActiveRecord
|
51
|
+
mount_normalizer :title, UpcaseNormalizer
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
custom normalizer works as following:
|
56
|
+
```ruby
|
57
|
+
blog = Blog.new
|
58
|
+
blog.title = 'awesome title'
|
59
|
+
blog.title #=> 'AWESOME TITLE'
|
60
|
+
```
|
61
|
+
### Plain Old Ruby Object
|
62
|
+
this gem dose not depends active_record, which mean we use this gem in
|
63
|
+
Plain Old Ruby Object.
|
30
64
|
|
31
|
-
|
65
|
+
## Versioning
|
66
|
+
This project uses [Semantic Versioning](https://semver.org/) for release numbering.
|
32
67
|
|
33
68
|
## Contributing
|
34
69
|
|
@@ -1,9 +1,16 @@
|
|
1
|
-
require "normalizer_jp/normalizers/hankaku_normalizer"
|
2
|
-
require "normalizer_jp/normalizers/katakana_normalizer"
|
3
|
-
require "normalizer_jp/normalizers/hiragana_normalizer"
|
4
|
-
|
5
1
|
module NormalizerJp
|
6
2
|
module Normalizers
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
def call(attribute_value)
|
6
|
+
raise NotImplementedError,
|
7
|
+
'Normalizer must implement call methods as class method'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
14
|
+
require "normalizer_jp/normalizers/hankaku_normalizer"
|
15
|
+
require "normalizer_jp/normalizers/katakana_normalizer"
|
16
|
+
require "normalizer_jp/normalizers/hiragana_normalizer"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalizer_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- koukikitamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|