ng_word 0.1.0 → 0.2.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/.github/workflows/release.yml +21 -0
- data/.github/workflows/ruby.yml +31 -0
- data/Makefile +28 -0
- data/README.md +3 -4
- data/compose.yaml +15 -0
- data/lib/ng_word/exclude_word_rule.rb +8 -12
- data/lib/ng_word/rule.rb +8 -9
- data/lib/ng_word/rule_list.rb +10 -5
- data/lib/ng_word/verification_result.rb +7 -1
- data/lib/ng_word/version.rb +1 -1
- data/ng_word.gemspec +3 -3
- metadata +22 -22
- data/.circleci/config.yml +0 -30
- data/.travis.yml +0 -7
- data/aaa +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76a4a48f1db69953deb1234d5fa2a2a3f8808e04eb1e556527502fcbd4e57ba3
|
|
4
|
+
data.tar.gz: 6507a13384276aa2bfe178b82cbdc57c45446e25ddaf3c0a5ecf8d7473506787
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de03cfd062eda421483e7501fcf1fa39cfad60a2cf969db0d5ac26842c7d0af77543a751328ad0d0db26afab1fe0e90a626b55ace30236237317dd54fb964b8a
|
|
7
|
+
data.tar.gz: 6fcc439a877ce8cf99bee925de7e013391c4bd235f1f89d21d2359eb1d7413ad084b5042c1bbfe11cc60cda57f66ea6c9c5eb7cba60923df5a88167852404740
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Release gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
rubygems-otp-code:
|
|
7
|
+
description: RubyGems OTP code
|
|
8
|
+
required: true
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
release-gem:
|
|
15
|
+
uses: taka0125/rubygems_release_workflow/.github/workflows/release.yml@v1
|
|
16
|
+
with:
|
|
17
|
+
rubygems-otp-code: ${{ github.event.inputs.rubygems-otp-code }}
|
|
18
|
+
user-email: taka0125@gmail.com
|
|
19
|
+
user-name: Takahiro Ooishi
|
|
20
|
+
secrets:
|
|
21
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
pull_request:
|
|
9
|
+
branches:
|
|
10
|
+
- main
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
ruby:
|
|
19
|
+
- '3.1'
|
|
20
|
+
- '3.2'
|
|
21
|
+
- '3.3'
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- uses: ruby/setup-ruby@v1
|
|
27
|
+
with:
|
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
|
29
|
+
bundler-cache: true
|
|
30
|
+
|
|
31
|
+
- run: bundle exec rspec
|
data/Makefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
DOCKER_COMPOSE = docker compose
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@grep "^[a-zA-Z][a-zA-Z0-9\-\/\_]*:" -o Makefile | grep -v "grep" | sed -e 's/^/make /' | sed -e 's/://'
|
|
5
|
+
build:
|
|
6
|
+
$(DOCKER_COMPOSE) build
|
|
7
|
+
up:
|
|
8
|
+
$(DOCKER_COMPOSE) up -d
|
|
9
|
+
down:
|
|
10
|
+
$(DOCKER_COMPOSE) stop
|
|
11
|
+
restart:
|
|
12
|
+
$(MAKE) down
|
|
13
|
+
$(MAKE) up
|
|
14
|
+
ps:
|
|
15
|
+
$(DOCKER_COMPOSE) ps
|
|
16
|
+
convert:
|
|
17
|
+
$(DOCKER_COMPOSE) convert
|
|
18
|
+
bundle/install: up
|
|
19
|
+
$(DOCKER_COMPOSE) exec ruby bash -c 'bundle install'
|
|
20
|
+
ruby/bash: up
|
|
21
|
+
$(DOCKER_COMPOSE) exec ruby bash
|
|
22
|
+
ruby/rspec: up
|
|
23
|
+
$(DOCKER_COMPOSE) exec ruby bash -c 'bundle exec rspec'
|
|
24
|
+
gem/release:
|
|
25
|
+
@read -p "Enter OTP code: " otp_code; \
|
|
26
|
+
gh workflow run release.yml -f rubygems-otp-code="$$otp_code"
|
|
27
|
+
console: up
|
|
28
|
+
$(DOCKER_COMPOSE) exec ruby bash -c './bin/console'
|
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# NgWord
|
|
2
2
|
|
|
3
|
+
[](https://rubygems.org/gems/ng_word)
|
|
4
|
+
[](https://github.com/taka0125/ng_word/actions)
|
|
5
|
+
|
|
3
6
|
Verify NG words.
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
@@ -38,10 +41,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
|
38
41
|
|
|
39
42
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
40
43
|
|
|
41
|
-
## Code Status
|
|
42
|
-
|
|
43
|
-
[](https://circleci.com/gh/taka0125/ng_word/tree/master)
|
|
44
|
-
|
|
45
44
|
## Contributing
|
|
46
45
|
|
|
47
46
|
Bug reports and pull requests are welcome on GitHub at https://github.com/taka0125/ng_word.
|
data/compose.yaml
ADDED
|
@@ -3,24 +3,20 @@ module NgWord
|
|
|
3
3
|
def initialize(downcased_ng_word, exclude_word)
|
|
4
4
|
@downcased_ng_word = downcased_ng_word
|
|
5
5
|
@exclude_word = exclude_word
|
|
6
|
+
@downcased_exclude_word = exclude_word.downcase
|
|
7
|
+
|
|
8
|
+
@index = @downcased_exclude_word.index(@downcased_ng_word)
|
|
9
|
+
@length = @downcased_exclude_word.length
|
|
10
|
+
|
|
11
|
+
freeze
|
|
6
12
|
end
|
|
7
13
|
|
|
8
14
|
def match?(downcased_text, matched_index)
|
|
9
|
-
downcased_text.slice(matched_index - index, length) ==
|
|
15
|
+
downcased_text.slice(matched_index - index, length) == downcased_exclude_word
|
|
10
16
|
end
|
|
11
17
|
|
|
12
18
|
private
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
@downcased_exclude_word ||= @exclude_word.downcase
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def index
|
|
19
|
-
@index ||= downcased_exclude_word.index(@downcased_ng_word)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def length
|
|
23
|
-
@length ||= downcased_exclude_word.length
|
|
24
|
-
end
|
|
20
|
+
attr_reader :downcased_ng_word, :exclude_word, :downcased_exclude_word, :index, :length
|
|
25
21
|
end
|
|
26
22
|
end
|
data/lib/ng_word/rule.rb
CHANGED
|
@@ -5,6 +5,11 @@ module NgWord
|
|
|
5
5
|
def initialize(ng_word, exclude_words: [])
|
|
6
6
|
@ng_word = ng_word
|
|
7
7
|
@exclude_words = exclude_words
|
|
8
|
+
|
|
9
|
+
@downcased_ng_word = @ng_word.downcase
|
|
10
|
+
@exclude_word_rules = Array(@exclude_words).map { |w| ExcludeWordRule.new(@downcased_ng_word, w) }
|
|
11
|
+
|
|
12
|
+
freeze
|
|
8
13
|
end
|
|
9
14
|
|
|
10
15
|
def verify(downcased_text, offset: 0)
|
|
@@ -15,7 +20,7 @@ module NgWord
|
|
|
15
20
|
return verify(downcased_text, offset: index + 1) if rule.match?(downcased_text, index)
|
|
16
21
|
end
|
|
17
22
|
|
|
18
|
-
VerificationResult.new(false, ng_word:
|
|
23
|
+
VerificationResult.new(false, ng_word: ng_word)
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def masked_text(text, replace_text: '***', for_monitoring: false)
|
|
@@ -33,7 +38,7 @@ module NgWord
|
|
|
33
38
|
end
|
|
34
39
|
words << text.slice(current_index, text.length - current_index)
|
|
35
40
|
|
|
36
|
-
replaced_text = for_monitoring ? "#{replace_text}(#{
|
|
41
|
+
replaced_text = for_monitoring ? "#{replace_text}(#{ng_word})" : replace_text
|
|
37
42
|
words.join(replaced_text)
|
|
38
43
|
end
|
|
39
44
|
|
|
@@ -44,13 +49,7 @@ module NgWord
|
|
|
44
49
|
|
|
45
50
|
private
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
@downcased_ng_word ||= @ng_word.downcase
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def exclude_word_rules
|
|
52
|
-
@exclude_word_rules ||= Array(@exclude_words).map { |w| ExcludeWordRule.new(downcased_ng_word, w) }
|
|
53
|
-
end
|
|
52
|
+
attr_reader :downcased_ng_word
|
|
54
53
|
|
|
55
54
|
def split(downcased_text, offset: 0, index_list: [])
|
|
56
55
|
index = downcased_text.index(downcased_ng_word, offset)
|
data/lib/ng_word/rule_list.rb
CHANGED
|
@@ -6,19 +6,20 @@ module NgWord
|
|
|
6
6
|
@rules[rule.ng_word.downcase] = rule
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
@ng_words = @rules.keys
|
|
10
9
|
@regexp = Regexp.union(@rules.keys.map { |s| /#{s}/i })
|
|
10
|
+
|
|
11
|
+
freeze
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def verify(text)
|
|
14
15
|
return VerificationResult.new(true) if text.blank?
|
|
15
16
|
|
|
16
|
-
candidate_ng_words = text.scan(
|
|
17
|
+
candidate_ng_words = text.scan(regexp)
|
|
17
18
|
return VerificationResult.new(true) if candidate_ng_words.blank?
|
|
18
19
|
|
|
19
20
|
downcased_text = text.downcase
|
|
20
21
|
candidate_ng_words.each do |ng_word|
|
|
21
|
-
rule =
|
|
22
|
+
rule = rules[ng_word.downcase]
|
|
22
23
|
next if rule.blank?
|
|
23
24
|
|
|
24
25
|
return VerificationResult.new(false, ng_word: rule.ng_word) if rule.match?(downcased_text)
|
|
@@ -30,11 +31,11 @@ module NgWord
|
|
|
30
31
|
def masked_text(text, replace_text: '***', for_monitoring: false)
|
|
31
32
|
return text if text.blank?
|
|
32
33
|
|
|
33
|
-
candidate_ng_words = text.scan(
|
|
34
|
+
candidate_ng_words = text.scan(regexp)
|
|
34
35
|
return text if candidate_ng_words.blank?
|
|
35
36
|
|
|
36
37
|
candidate_ng_words.each do |ng_word|
|
|
37
|
-
rule =
|
|
38
|
+
rule = rules[ng_word.downcase]
|
|
38
39
|
next if rule.blank?
|
|
39
40
|
|
|
40
41
|
text = rule.masked_text(text, replace_text: replace_text, for_monitoring: for_monitoring)
|
|
@@ -47,5 +48,9 @@ module NgWord
|
|
|
47
48
|
result = verify(text)
|
|
48
49
|
!result.valid?
|
|
49
50
|
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
attr_reader :rules, :regexp
|
|
50
55
|
end
|
|
51
56
|
end
|
data/lib/ng_word/version.rb
CHANGED
data/ng_word.gemspec
CHANGED
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
spec.require_paths = ["lib"]
|
|
24
24
|
|
|
25
25
|
spec.add_dependency "activesupport"
|
|
26
|
-
spec.add_development_dependency "bundler"
|
|
27
|
-
spec.add_development_dependency "rake"
|
|
28
|
-
spec.add_development_dependency "rspec"
|
|
26
|
+
spec.add_development_dependency "bundler"
|
|
27
|
+
spec.add_development_dependency "rake"
|
|
28
|
+
spec.add_development_dependency "rspec"
|
|
29
29
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ng_word
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takahiro Ooishi
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -28,44 +28,44 @@ dependencies:
|
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rake
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: rspec
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '0'
|
|
69
69
|
description: Verify NG words.
|
|
70
70
|
email:
|
|
71
71
|
- taka0125@gmail.com
|
|
@@ -73,17 +73,18 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
-
- ".
|
|
76
|
+
- ".github/workflows/release.yml"
|
|
77
|
+
- ".github/workflows/ruby.yml"
|
|
77
78
|
- ".gitignore"
|
|
78
79
|
- ".rspec"
|
|
79
|
-
- ".travis.yml"
|
|
80
80
|
- Gemfile
|
|
81
81
|
- LICENSE
|
|
82
|
+
- Makefile
|
|
82
83
|
- README.md
|
|
83
84
|
- Rakefile
|
|
84
|
-
- aaa
|
|
85
85
|
- bin/console
|
|
86
86
|
- bin/setup
|
|
87
|
+
- compose.yaml
|
|
87
88
|
- lib/ng_word.rb
|
|
88
89
|
- lib/ng_word/exclude_word_rule.rb
|
|
89
90
|
- lib/ng_word/rule.rb
|
|
@@ -94,7 +95,7 @@ files:
|
|
|
94
95
|
homepage: https://github.com/taka0125/ng_word
|
|
95
96
|
licenses: []
|
|
96
97
|
metadata: {}
|
|
97
|
-
post_install_message:
|
|
98
|
+
post_install_message:
|
|
98
99
|
rdoc_options: []
|
|
99
100
|
require_paths:
|
|
100
101
|
- lib
|
|
@@ -109,9 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
109
110
|
- !ruby/object:Gem::Version
|
|
110
111
|
version: '0'
|
|
111
112
|
requirements: []
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
signing_key:
|
|
113
|
+
rubygems_version: 3.4.19
|
|
114
|
+
signing_key:
|
|
115
115
|
specification_version: 4
|
|
116
116
|
summary: Verify NG words.
|
|
117
117
|
test_files: []
|
data/.circleci/config.yml
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
version: 2
|
|
2
|
-
|
|
3
|
-
jobs:
|
|
4
|
-
build: &build
|
|
5
|
-
docker:
|
|
6
|
-
- image: circleci/ruby:latest
|
|
7
|
-
steps:
|
|
8
|
-
- checkout
|
|
9
|
-
- run:
|
|
10
|
-
name: Install gems
|
|
11
|
-
command: bundle install
|
|
12
|
-
- run:
|
|
13
|
-
name: RSpec
|
|
14
|
-
command: rspec
|
|
15
|
-
ruby-2.4:
|
|
16
|
-
<<: *build
|
|
17
|
-
docker:
|
|
18
|
-
- image: circleci/ruby:2.4
|
|
19
|
-
|
|
20
|
-
ruby-2.5:
|
|
21
|
-
<<: *build
|
|
22
|
-
docker:
|
|
23
|
-
- image: circleci/ruby:2.5
|
|
24
|
-
|
|
25
|
-
workflows:
|
|
26
|
-
version: 2
|
|
27
|
-
build-multiple-rubies:
|
|
28
|
-
jobs:
|
|
29
|
-
- ruby-2.4
|
|
30
|
-
- ruby-2.5
|
data/.travis.yml
DELETED
data/aaa
DELETED
|
File without changes
|