amakanize 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d592c1c44897590e526b7d614c8aed78e6ea5d0a
4
- data.tar.gz: 84063288b8a6901ea667eed70e9235ccf1263ccd
3
+ metadata.gz: a8d34cba3811141a46de4311a4842da44b06fbf3
4
+ data.tar.gz: b717fcc757fead1743d1fe644a96f50243a15bdc
5
5
  SHA512:
6
- metadata.gz: 7fa3c2bb7591740afd09647ceb35c115c7cbe6a92c9d9c294549f1b8939d8106dee96b5db2ac2eb16909c09a76d9f7a8fa20fa5bbf68e80a53a7e7d179d1e27a
7
- data.tar.gz: d955844fa450b730ce4d47f45ab89e35675a031cfa2cd60f35a25ce013020445f64e9052b3e223754e761f2d4e5b5ff0fd1fe18e92ac1b1ab3cb110ccd68307b
6
+ metadata.gz: 113dd0b8d000dadb813814604d02f2db94d37f087ba2288ccdcae009d14b631ed0ccc9cc354b1aebe4af0daa5c244d1e8c703436e67af8a72f741b55856c9fad
7
+ data.tar.gz: 167decb78e0f2628df666e3a1f906198a8974d098e28f498dc2642fea43ef2d842ed9dbd3239bce5818d26ac129bbd1ac5755d8771eca9e45d0715d8463833f4
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
+ --format doc
2
3
  --require spec_helper
data/CHANGELOG.md CHANGED
@@ -1,2 +1,9 @@
1
+ ## 0.0.2
2
+ - Remove parentheses of numericals in author name
3
+ - Remove role name from author name
4
+ - Remove trailing payload from author name
5
+ - Strip author name
6
+ - Unescape HTML in author name
7
+
1
8
  ## 0.0.1
2
9
  - 1st release :tada:
@@ -1,173 +1,18 @@
1
- require "active_support"
2
-
3
1
  module Amakanize
4
2
  class AuthorName
5
- ENCLOSED_ALPHANUMERICS = %w(
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
- )
3
+ class << self
4
+ # @return [Array<Amakan::Filters::BaseFilter>]
5
+ def filters
6
+ @filters ||= [
7
+ ::Amakanize::Filters::HtmlUnescapeFilter.new,
8
+ ::Amakanize::Filters::NormalizationFilter.new,
9
+ ::Amakanize::Filters::ParenthesesDeletionFilter.new,
10
+ ::Amakanize::Filters::RoleNameDeletionFilter.new,
11
+ ::Amakanize::Filters::StripFilter.new,
12
+ ::Amakanize::Filters::TrailingPayloadDeletionFilter.new,
13
+ ]
14
+ end
15
+ end
171
16
 
172
17
  # @param raw [String]
173
18
  def initialize(raw)
@@ -176,11 +21,8 @@ module Amakanize
176
21
 
177
22
  # @note Override
178
23
  def to_s
179
- ENCLOSED_ALPHANUMERICS.inject(@raw) do |result, enclosed_alphanumerics|
180
- result.gsub(enclosed_alphanumerics) do |matched_string|
181
- half_size_alphanumerics = ::ActiveSupport::Multibyte::Unicode.normalize(matched_string)
182
- "(#{half_size_alphanumerics})"
183
- end
24
+ self.class.filters.inject(@raw) do |result, filter|
25
+ filter.call(result)
184
26
  end
185
27
  end
186
28
  end
@@ -0,0 +1,11 @@
1
+ module Amakanize
2
+ module Filters
3
+ class BaseFilter
4
+ # @param string [String]
5
+ # @return [String]
6
+ def call(string)
7
+ raise ::NotImplementedError
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require "cgi"
2
+
3
+ module Amakanize
4
+ module Filters
5
+ class HtmlUnescapeFilter < BaseFilter
6
+ # @note Override
7
+ # @param string [String] e.g. `"&lt;ハノカゲ&gt;"`
8
+ # @return [String] e.g. `"ハノカゲ"`
9
+ def call(string)
10
+ ::CGI.unescapeHTML(string)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,183 @@
1
+ require "active_support"
2
+
3
+ module Amakanize
4
+ module Filters
5
+ class NormalizationFilter < BaseFilter
6
+ ENCLOSED_ALPHANUMERICS_COLLECTION = %w(
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ )
172
+
173
+ # @note Override
174
+ def call(string)
175
+ ENCLOSED_ALPHANUMERICS_COLLECTION.inject(string) do |result, enclosed_alphanumerics|
176
+ result.gsub(enclosed_alphanumerics) do |matched_string|
177
+ ::ActiveSupport::Multibyte::Unicode.normalize(matched_string)
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,12 @@
1
+ module Amakanize
2
+ module Filters
3
+ class ParenthesesDeletionFilter < BaseFilter
4
+ # @note Override
5
+ # @param string [String] e.g. `"ぽんかん(8)"`
6
+ # @return [String] e.g. `"ぽんかん8"`
7
+ def call(string)
8
+ string.gsub(/\((\d+)\)/, '\1')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Amakanize
2
+ module Filters
3
+ class RoleNameDeletionFilter < BaseFilter
4
+ ROLE_NAMES = %w(
5
+ 原作
6
+ 原案
7
+ 漫画
8
+ )
9
+
10
+ # @note Override
11
+ # @param string [String] e.g. `"漫画:ハノカゲ"`
12
+ # @return [String] e.g. `"ハノカゲ"`
13
+ def call(string)
14
+ string.gsub(%r<\A#{::Regexp.union(ROLE_NAMES)}[:/]>, "")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Amakanize
2
+ module Filters
3
+ class StripFilter < BaseFilter
4
+ # @note Override
5
+ # @param string [String] e.g. `"  ハノカゲ  "`
6
+ # @return [String] e.g. `"ハノカゲ"`
7
+ def call(string)
8
+ string.gsub(/\A[[:space:]]+/, "").gsub(/[[:space:]]+\z/, "")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Amakanize
2
+ module Filters
3
+ class TrailingPayloadDeletionFilter < BaseFilter
4
+ PAYLOADS = %w(
5
+ その他
6
+ ほか
7
+
8
+ )
9
+
10
+ # @note Override
11
+ # @param string [String] e.g. `"ハノカゲ ほか"`
12
+ # @return [String] e.g. `"ハノカゲ"`
13
+ def call(string)
14
+ string.gsub(/[[:space:]]+#{::Regexp.union(PAYLOADS)}\z/, "")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Amakanize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/amakanize.rb CHANGED
@@ -1,3 +1,10 @@
1
1
  require "amakanize/author_name"
2
+ require "amakanize/filters/base_filter"
3
+ require "amakanize/filters/html_unescape_filter"
4
+ require "amakanize/filters/normalization_filter"
5
+ require "amakanize/filters/parentheses_deletion_filter"
6
+ require "amakanize/filters/role_name_deletion_filter"
7
+ require "amakanize/filters/strip_filter"
8
+ require "amakanize/filters/trailing_payload_deletion_filter"
2
9
  require "amakanize/series_name"
3
10
  require "amakanize/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amakanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - r7kamura
@@ -86,6 +86,13 @@ files:
86
86
  - bin/setup
87
87
  - lib/amakanize.rb
88
88
  - lib/amakanize/author_name.rb
89
+ - lib/amakanize/filters/base_filter.rb
90
+ - lib/amakanize/filters/html_unescape_filter.rb
91
+ - lib/amakanize/filters/normalization_filter.rb
92
+ - lib/amakanize/filters/parentheses_deletion_filter.rb
93
+ - lib/amakanize/filters/role_name_deletion_filter.rb
94
+ - lib/amakanize/filters/strip_filter.rb
95
+ - lib/amakanize/filters/trailing_payload_deletion_filter.rb
89
96
  - lib/amakanize/series_name.rb
90
97
  - lib/amakanize/version.rb
91
98
  homepage: https://github.com/amakan/amakanize