privacy_mask_tools 0.1.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in privacy_mask_tools.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'yard'
8
+ gem 'rdiscount'
9
+ gem 'guard-rspec', require: false
10
+ gem 'libnotify', require: false
11
+ gem 'rb-inotify', require: false
12
+ gem 'rb-fsevent', require: false
13
+ gem 'growl', require: false
14
+ end
15
+
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ guard 'rspec', version: 2, cli: '--color --format nested --fail-fast', all_on_start: false do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/privacy_mask_tools/(.+)\.rb$}) { |m| "spec/privacy_mask_tools/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec/" }
5
+ watch('lib/privacy_mask_tools.rb') { "spec/" }
6
+ end
7
+
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ # PrivacyMaskTools
2
+
3
+ 個人情報らしきものを判定・マスキングします
4
+
5
+ ## install
6
+
7
+ <pre><code>gem 'privacy_mask_tools'</code></pre>
8
+
9
+ ## How to use
10
+
11
+ <pre><code>PrivacyMaskTools::Base.has_mobile_number?("090-1234-5678")
12
+ # => true
13
+ PrivacyMaskTools::Base.mobile_number_masking("私の携帯電話番号は 090-1234-5678 です")
14
+ # => "私の携帯電話番号は ***-****-**** です"
15
+ </code></pre>
16
+
17
+ ## You can include PrivacyMaskTools methods in your object
18
+
19
+ in your object
20
+ <pre><code>class Obj
21
+ include PrivacyMaskTools::Matcher
22
+ # ... todo something
23
+ end</code></pre>
24
+
25
+ <pre><code>x = Obj.new
26
+ x.mobile_number_masking</code></pre>
27
+
28
+ ## Copyright
29
+
30
+ Copyright (c) 2011 NAMAKESUGI, released under the MIT license
31
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = FileList['spec/**/*_spec.rb']
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
12
+ spec.pattern = 'spec/**/*_spec.rb'
13
+ spec.rcov = true
14
+ end
15
+
16
+ require 'yard'
17
+ require 'yard/rake/yardoc_task'
18
+ YARD::Rake::YardocTask.new do |t|
19
+ t.files = ['lib/forgery_ja/**/*.rb']
20
+ t.options = []
21
+ t.options << '--debug' << '--verbose' if $trace
22
+ end
23
+
24
+ task :default => :spec
25
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'privacy_mask_tools'
2
+
@@ -0,0 +1,4 @@
1
+ require "privacy_mask_tools/version"
2
+ require "privacy_mask_tools/matcher"
3
+ require "privacy_mask_tools/base"
4
+
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ # PrivacyMaskTools::Matcherをincludeしselfで使用できるようにしています
4
+ class PrivacyMaskTools::Base
5
+ class << self
6
+ include PrivacyMaskTools::Matcher
7
+ end
8
+ end
9
+
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ module PrivacyMaskTools::Matcher
4
+ MOBILE_NUMBER_REGEXP = /(([00][7-97-9][00])[-ー)(()  ]*([0-90-9]{4})[-ー)(()  ]*([0-90-9]{4})(?![0-90-9]))/
5
+ JARGON_MOBILE_NUMBER_REGEXP = /(([00oO〇十]?[7-97-9⑦⑧⑨][00十〇])[-ー)(()  ]*([0-90-9oO①②③④⑤⑥⑦⑧⑨一二三四五六七八九十〇壱弐参]{4})[-ー)(()  ]*([0-90-9oO①②③④⑤⑥⑦⑧⑨一二三四五六七八九十〇壱弐参]{4})(?![0-90-9]))/
6
+
7
+ # 携帯電話番号が含まれているかチェックします
8
+ # 隠語判定はソフトで、半角全角の携帯番号らしきものはtrueを返します
9
+ # @param String チェック対象の文字列
10
+ # @param Boolean 隠語判定強化フラグ(漢数字・丸付き数値にもマッチ)
11
+ # @return Boolean
12
+ # 含まれている場合 true
13
+ # 含まれていない場合 false
14
+ def has_mobile_number?(text, jargon=false)
15
+ reg = jargon ? JARGON_MOBILE_NUMBER_REGEXP : MOBILE_NUMBER_REGEXP
16
+ !text.match(reg).nil?
17
+ end
18
+
19
+ # 携帯番号が含まれているかチェックします
20
+ # 隠語らしきものも判定します
21
+ # そのため正常な文字列も置換する確率が高くなります
22
+ # 現時点ではテストが不十分です
23
+ # @param String チェック対象の文字列
24
+ # @return Boolean
25
+ # 含まれている場合 true
26
+ # 含まれていない場合 false
27
+ def has_jargon_mobile_number?(text)
28
+ has_mobile_number?(text,true)
29
+ end
30
+
31
+ # 電話番号らしき箇所をマスキングします
32
+ # @param String マスキング対象の文字列
33
+ # @param String ('*') マスキング後の文字列
34
+ # @param Boolean false 隠語判定を強化フラグ
35
+ def mobile_number_masking(text, sub="*", jargon=false)
36
+ reg = jargon ? JARGON_MOBILE_NUMBER_REGEXP : MOBILE_NUMBER_REGEXP
37
+ text.scan(reg).each do |f|
38
+ replace_word = f[0].dup
39
+ f.each_with_index do |g, index|
40
+ next if index == 0
41
+ replace_word.sub!(g, sub*g.size)
42
+ end
43
+ text = text.sub(f[0], replace_word)
44
+ end
45
+ text
46
+ end
47
+ end
48
+
@@ -0,0 +1,4 @@
1
+ module PrivacyMaskTools
2
+ VERSION = "0.1.1"
3
+ end
4
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "privacy_mask_tools/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "privacy_mask_tools"
7
+ s.version = PrivacyMaskTools::VERSION
8
+ s.authors = ["namakesugi"]
9
+ s.email = ["info@namakesugi.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{privacy data masking tools for japanese}
12
+ s.description = %q{Included methods "has_mobile_number?", "mobile_number_masking"}
13
+
14
+ s.rubyforge_project = "privacy_mask_tools"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rspec', '~> 2.6.0'
22
+ s.add_development_dependency 'tapp', '~> 1.0.0'
23
+ end
24
+
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe PrivacyMaskTools::Base do
5
+ describe "#has_mobile_number?" do
6
+ it { PrivacyMaskTools::Base.has_mobile_number?("私の携帯電話番号は 090-1234-5678 です").should be_true }
7
+ end
8
+ describe "#has_jargon_mobile_number?" do
9
+ it { PrivacyMaskTools::Base.has_jargon_mobile_number?("私の携帯電話番号は 090-1234-5678 です").should be_true }
10
+ end
11
+ describe "#mobile_number_masking" do
12
+ it { PrivacyMaskTools::Base.mobile_number_masking("私の携帯電話番号は 090-1234-5678 です").should eql "私の携帯電話番号は ***-****-**** です" }
13
+ end
14
+ end
15
+
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe PrivacyMaskTools::Matcher do
6
+ class Obj
7
+ include PrivacyMaskTools::Matcher
8
+ end
9
+
10
+ let!(:matcher) { Obj.new }
11
+
12
+ describe ".has_mobile_number?" do
13
+ describe "携帯番号が含まれている" do
14
+ it { matcher.has_mobile_number?("09012345678").should be_true }
15
+ it { matcher.has_mobile_number?("090-1234-5678").should be_true }
16
+ it { matcher.has_mobile_number?("a090-1234-5678a").should be_true }
17
+ context "連続する数値中に含まれる場合" do
18
+ it { matcher.has_mobile_number?("009012345678").should be_true }
19
+ end
20
+ context "スペースが含まれる場合" do
21
+ it { matcher.has_mobile_number?("090 1234 5678").should be_true }
22
+ it { matcher.has_mobile_number?("090 (1234) 5678").should be_true }
23
+ end
24
+ context "全角数字が含まれている場合" do
25
+ it { matcher.has_mobile_number?("09012345678").should be_true }
26
+ it { matcher.has_mobile_number?("090(1234)5678").should be_true }
27
+ end
28
+ end
29
+
30
+ describe "携帯番号が含まれていない" do
31
+ it { matcher.has_mobile_number?("あいうえおaiueo").should be_false }
32
+ it { matcher.has_mobile_number?("19012345678").should be_false }
33
+ it { matcher.has_mobile_number?("09112345678").should be_false }
34
+
35
+ context "携帯番号+数値の場合" do
36
+ subject { matcher.has_mobile_number?("090123456781") }
37
+ it { should be_false }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe ".has_jargon_mobile_number" do
43
+ it { matcher.has_jargon_mobile_number?("0⑨0-1②参四-oO十〇").should be_true }
44
+ end
45
+
46
+ describe ".mobile_number_masking" do
47
+ it { matcher.mobile_number_masking("090-1234-5678").should eql "***-****-****" }
48
+ it { matcher.mobile_number_masking("09012345678","x").should eql "xxxxxxxxxxx" }
49
+ context "複数マッチする箇所がある場合" do
50
+ it { matcher.mobile_number_masking("abc:090-1234-5678\n090 090-1111-2222").should eql "abc:***-****-****\n090 ***-****-****" }
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ require 'rspec'
3
+ require 'tapp'
4
+ require File.expand_path(File.dirname(__FILE__) + '/../init')
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: privacy_mask_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - namakesugi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &73532920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.6.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *73532920
25
+ - !ruby/object:Gem::Dependency
26
+ name: tapp
27
+ requirement: &73532670 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *73532670
36
+ description: Included methods "has_mobile_number?", "mobile_number_masking"
37
+ email:
38
+ - info@namakesugi.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Guardfile
46
+ - README.markdown
47
+ - Rakefile
48
+ - init.rb
49
+ - lib/privacy_mask_tools.rb
50
+ - lib/privacy_mask_tools/base.rb
51
+ - lib/privacy_mask_tools/matcher.rb
52
+ - lib/privacy_mask_tools/version.rb
53
+ - privacy_mask_tools.gemspec
54
+ - spec/privacy_mask_tools/base_spec.rb
55
+ - spec/privacy_mask_tools/matcher_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: ''
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project: privacy_mask_tools
77
+ rubygems_version: 1.8.6
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: privacy data masking tools for japanese
81
+ test_files: []