privacy_mask_tools 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,6 +7,8 @@ group :development, :test do
7
7
  gem 'yard'
8
8
  gem 'rdiscount'
9
9
  gem 'guard-rspec', require: false
10
+ # gem 'rspec-pride', require: false
11
+ gem 'fuubar', require: false
10
12
  gem 'libnotify', require: false
11
13
  gem 'rb-inotify', require: false
12
14
  gem 'rb-fsevent', require: false
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard 'rspec', version: 2, cli: '--color --format nested --fail-fast', all_on_start: false do
1
+ guard 'rspec', version: 2, cli: '--color --format Fuubar --fail-fast', all_on_start: false do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/privacy_mask_tools/(.+)\.rb$}) { |m| "spec/privacy_mask_tools/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec/" }
data/README.markdown CHANGED
@@ -12,18 +12,41 @@
12
12
  # => true
13
13
  PrivacyMaskTools::Base.mobile_number_masking("私の携帯電話番号は 090-1234-5678 です")
14
14
  # => "私の携帯電話番号は ***-****-**** です"
15
+ PrivacyMaskTools::Base.pick_mobile_number("私の携帯電話番号は 090-1234-5678 です")
16
+ # => ["090-1234-5678"]
15
17
  </code></pre>
16
18
 
19
+ ## Module Infomation
20
+
21
+ ### PrivacyMaskTools::PhoneMatcher
22
+
23
+ * has_mobile_number?
24
+ * has_phone_number?
25
+ * mobile_number_masking
26
+ * phone_nomber_masking
27
+ * pick_mobile_number
28
+ * pick_phone_number
29
+
30
+ ### PrivacyMaskTools::EmailMatcher
31
+
32
+ * has_rfc_email?("<text data>") # => return true or false
33
+ * pick_rfc_email("<text data>") # => return Array
34
+ * rfc_email_masking("<text data>", "<masking words>") # => return masked text_data
35
+
17
36
  ## You can include PrivacyMaskTools methods in your object
18
37
 
19
38
  in your object
20
39
  <pre><code>class Obj
21
- include PrivacyMaskTools::Matcher
40
+ include PrivacyMaskTools::PhoneMatcher
41
+ include PrivacyMaskTools::EmailMatcher
22
42
  # ... todo something
23
43
  end</code></pre>
24
44
 
25
45
  <pre><code>x = Obj.new
26
- x.mobile_number_masking</code></pre>
46
+ x.has_mobile_number?("080-0000-0000")
47
+ # => true
48
+ x.has_rfc_email?("xxxx@example.com")
49
+ # => true</code></pre>
27
50
 
28
51
  ## Note on Patches/Pull Requests
29
52
 
@@ -1,4 +1,5 @@
1
1
  require "privacy_mask_tools/version"
2
- require "privacy_mask_tools/matcher"
2
+ require "privacy_mask_tools/phone_matcher"
3
+ require "privacy_mask_tools/email_matcher"
3
4
  require "privacy_mask_tools/base"
4
5
 
@@ -5,7 +5,8 @@
5
5
  # PrivacyMaskTools::Base.mobile_number_masking("#{target_text}")
6
6
  class PrivacyMaskTools::Base
7
7
  class << self
8
- include PrivacyMaskTools::Matcher
8
+ include PrivacyMaskTools::PhoneMatcher
9
+ include PrivacyMaskTools::EmailMatcher
9
10
  end
10
11
  end
11
12
 
@@ -0,0 +1,75 @@
1
+ # coding: utf-8
2
+
3
+ # Email判定用モジュール
4
+ module PrivacyMaskTools::EmailMatcher
5
+
6
+ # RFC5322形式に近いメールアドレスが存在するかチェックします
7
+ # @param [String] 探索対象文字列
8
+ # @return [Boolean]
9
+ def has_rfc_email?(text)
10
+ !text.match(make_rfc_regexp).nil?
11
+ end
12
+
13
+ # RFC5322形式に近いメールアドレスを抽出します
14
+ # @param [String] 探索対象文字列
15
+ # @return [Array]
16
+ def pick_rfc_email(text)
17
+ [].tap { |o|
18
+ text.scan(make_rfc_regexp) { |f| o << f[0] }
19
+ }
20
+ end
21
+
22
+ # RFC5322形式に近いメールアドレスをマスキングします
23
+ # @param [String] 探索対象文字列
24
+ # @param [String] 置換文字列
25
+ # @return [String] 置換後の文字列
26
+ def rfc_email_masking(text, words="***")
27
+ text.dup.tap {|o| text.scan(make_rfc_regexp) { |f| o.sub!(f[0], words) } }
28
+ end
29
+
30
+ # ----- メールアドレス正規表現メソッド -----
31
+
32
+ # RFC5322 に対応した正規表現を生成します
33
+ # 概ね対応しているレベルであり、完全に対応しているわけではありません
34
+ #
35
+ # validates_email_format_ofを参考にしています
36
+ # @see https://github.com/alexdunae/validates_email_format_of
37
+ # TODO chache
38
+ def make_rfc_regexp
39
+ Regexp.new('(('+ unquoted_regexp + '|' + quoted_regexp + '+)@(' + domain_regexp + '))')
40
+ end
41
+
42
+ # メールアドレスのローカル部で使用可能な特殊記号
43
+ # @return [String] エスケープ処理された特殊記号
44
+ def special_char
45
+ Regexp.escape('!#$%&\'*-/=?+-^_`{|}~')
46
+ end
47
+
48
+ # メールアドレスのローカル部のダブルクウォーテーションで囲まれた部分で使用可能な特殊記号
49
+ # @return [String] エスケープ処理された特殊記号
50
+ def quoted_special_char
51
+ Regexp.escape('()<>[]:;@, ')
52
+ end
53
+
54
+ # メールアドレスのローカル部の正規表現文字列
55
+ # このままだと文字列ですので、Regexp.new等で正規表現に変換する必要があります
56
+ # @return [String] 正規表現文字列
57
+ def unquoted_regexp
58
+ "([[0-9A-Za-z]#{special_char}]+[\.]+)*[[0-9A-Za-z]#{special_char}+]+"
59
+ end
60
+
61
+ # メールアドレスのローカル部において ダブルクウォーテーションで囲まれている部分の正規表現文字列
62
+ # このままだと文字列ですので、Regexp.new等で正規表現に変換する必要があります
63
+ # @return [String] 正規表現文字列
64
+ def quoted_regexp
65
+ "\"[0-9A-Za-z#{special_char}#{quoted_special_char}\.]*\""
66
+ end
67
+
68
+ # メールアドレスのドメイン部の正規表現文字列
69
+ # このままだと文字列ですので、Regexp.new等で正規表現に変換する必要があります
70
+ # @return [String] 正規表現文字列
71
+ def domain_regexp
72
+ "((\w+\-+[^_])|(\w+\.[-a-z0-9]*))*([-a-z0-9\.]{1,63})\.[a-z]{2,6}(?:\.[a-z]{2,6})?"
73
+ end
74
+ end
75
+
@@ -1,19 +1,19 @@
1
1
  # coding: utf-8
2
2
 
3
- # 個人情報Matcher
4
- # 判定・マスキング・抽出の3つの機能を保持しています
5
- module PrivacyMaskTools::Matcher
6
- # 携帯番号+IPフォン ソフト判定用正規表現
7
- MOBILE_NUMBER_REGEXP = /([((]?([00][557-97-9][00])[-ー()()・  ]*([0-90-9]{4})[-ー()()・  ]*([0-90-9]{4})(?![0-90-9]))/
3
+ # 電話番号判定用モジュール
4
+ module PrivacyMaskTools::PhoneMatcher
8
5
 
9
- # 携帯番号+IPフォン ハード判定用正規表現
10
- JARGON_MOBILE_NUMBER_REGEXP = /([((]?([00oO〇十]?[55⑤五7-97-9⑦-⑨七-九][00十〇])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})(?![0-90-9]))/
6
+ # 携帯番号 ソフト判定用正規表現
7
+ MOBILE_NUMBER_REGEXP = /([((]?([00][7-97-9][0])[-ー()()・  ]*([0-90-9]{4})[-ー()()・  ]*([0-90-9]{4})(?![0-90-9]))/
11
8
 
12
- # 固定電話 ソフト判定用正規表現
13
- PHONE_NUMBER_REGEXP = /([((]?(([00][334466])[-ー()()・  ]*([0-90-9]{4})|([00][1-91-9]{2})[-ー()()・  ]*([0-90-9]{3})|([00][1-91-9]{2}[0-90-9])[-ー()()・  ]*([0-90-9]{2})|([00][1-91-9]{2}[0-90-9]{2})[-ー()()・  ]*([0-90-9]))[-ー()()・  ]*([0-90-9]{4})(?![0-90-9]))/
9
+ # 携帯番号 ハード判定用正規表現
10
+ JARGON_MOBILE_NUMBER_REGEXP = /([((]?([00oO〇十]?[7-97-9⑦-⑨七-九][00oO〇十])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})(?![0-90-9]))/
14
11
 
15
- # 固定電話 ハード判定用正規表現
16
- JARGON_PHONE_NUMBER_REGEXP = /([((]?(([00oO〇十][33三参③44四④66六⑥])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{3})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2}[0-90-9oO①-⑨一-四〇壱弐参])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{2})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2}[0-90-9oO①-⑨一-四〇壱弐参]{2})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]))[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})(?![0-90-9]))/
12
+ # 固定電話(IP電話込) ソフト判定用正規表現
13
+ PHONE_NUMBER_REGEXP = /([((]?(([00][346])[-ー()()・  ]*([0-90-9]{4})|([00][1-91-9]{2})[-ー()()・  ]*([0-90-9]{3})|([00][1-91-9]{2}[0-90-9])[-ー()()・  ]*([0-90-9]{2})|([00][1-91-9]{2}[0-90-9]{2})[-ー()()・  ]*([0-90-9])|([00][55][00])[-ー()()・  ]*([0-90-9]{4}))[-ー()()・  ]*([0-90-9]{4})(?![0-90-9]))/
14
+
15
+ # 固定電話(IP電話込) ハード判定用正規表現
16
+ JARGON_PHONE_NUMBER_REGEXP = /([((]?(([00oO〇十][33三参③44四④66六⑥])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{3})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2}[0-90-9oO①-⑨一-四〇壱弐参])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{2})|([00oO〇十][1-91-9一-九四①-⑨壱弐参]{2}[0-90-9oO①-⑨一-四〇壱弐参]{2})[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参])|([00oO〇十][55五⑤][00oO〇十])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4}))[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})(?![0-90-9]))/
17
17
 
18
18
  # 携帯番号が含まれているかチェックします
19
19
  # jargonをfalseにした場合は判定条件はゆるめです
@@ -120,5 +120,22 @@ module PrivacyMaskTools::Matcher
120
120
  text
121
121
  end
122
122
 
123
+ # text中に含まれる固定電話番号を抽出します
124
+ # @param [String] 探索対象文字列
125
+ # @param [Boolean] Jargonモードを利用するか
126
+ # @return [Array]
127
+ def pick_phone_number(text, jargon=false)
128
+ reg = jargon ? JARGON_PHONE_NUMBER_REGEXP : PHONE_NUMBER_REGEXP
129
+ [].tap { |o| text.scan(reg).each { |f| o << f[0] } }
130
+ end
131
+
132
+ # text中に含まれる携帯番号を抽出します
133
+ # @param [String] 探索対象文字列
134
+ # @param [Boolean] Jargonモードを利用するか
135
+ # @return [Array]
136
+ def pick_mobile_number(text, jargon=false)
137
+ reg = jargon ? JARGON_MOBILE_NUMBER_REGEXP : MOBILE_NUMBER_REGEXP
138
+ [].tap { |o| text.scan(reg).each { |f| o << f[0] } }
139
+ end
123
140
  end
124
141
 
@@ -1,6 +1,6 @@
1
1
  # VERSION NUMBER
2
2
  module PrivacyMaskTools
3
3
  # Setted Version Number
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
 
@@ -6,10 +6,41 @@ describe PrivacyMaskTools::Base do
6
6
  it { PrivacyMaskTools::Base.has_mobile_number?("私の携帯電話番号は 090-1234-5678 です").should be_true }
7
7
  end
8
8
  describe "#has_jargon_mobile_number?" do
9
- it { PrivacyMaskTools::Base.has_jargon_mobile_number?("私の携帯電話番号は 090-1234-5678 です").should be_true }
9
+ it { PrivacyMaskTools::Base.has_jargon_mobile_number?("私の携帯電話番号は 〇九O-①②③④-⑤⑥⑦⑧ です").should be_true }
10
10
  end
11
11
  describe "#mobile_number_masking" do
12
12
  it { PrivacyMaskTools::Base.mobile_number_masking("私の携帯電話番号は 090-1234-5678 です").should eql "私の携帯電話番号は ***-****-**** です" }
13
13
  end
14
+
15
+ describe "#has_phone_number?" do
16
+ it { PrivacyMaskTools::Base.has_phone_number?("私の電話番号は 03-0000-0000 です").should be_true }
17
+ end
18
+
19
+ describe "#has_jargon_phone_number?" do
20
+ it { PrivacyMaskTools::Base.has_jargon_phone_number?("私の電話番号は 〇三ー壱弐参四ー五六七八 です").should be_true }
21
+ end
22
+
23
+ describe "#phone_nomber_masking" do
24
+ it { PrivacyMaskTools::Base.phone_nomber_masking("私の電話番号は 03-0000-0000 です\r\n私のFAX番号は 03ー0000ー0000 です").should
25
+ eql "私の電話番号は xx-xxxx-xxxx です\r\n私のFAX番号は xxーxxxxーxxxx です" }
26
+ end
27
+
28
+ describe "#has_rfc_email?" do
29
+ it { PrivacyMaskTools::Base.has_rfc_email?("hogehoge@namaeksugi.net").should be_true }
30
+ end
31
+
32
+ describe "#has_rfc_email?" do
33
+ it { PrivacyMaskTools::Base.has_rfc_email?("hogehoge@namaeksugi.net").should be_true }
34
+ end
35
+
36
+ describe "#pick_rfc_email" do
37
+ subject { PrivacyMaskTools::Base.pick_rfc_email("お問い合わせは info@namakesugi.net まで") }
38
+ its([0]) { should eql "info@namakesugi.net" }
39
+ end
40
+
41
+ describe "#rfc_email_masking" do
42
+ subject { PrivacyMaskTools::Base.rfc_email_masking("お問い合わせは info@namakesugi.net まで") }
43
+ it { should eql "お問い合わせは *** まで" }
44
+ end
14
45
  end
15
46
 
@@ -0,0 +1,95 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe PrivacyMaskTools::EmailMatcher do
6
+ class Obj
7
+ include PrivacyMaskTools::EmailMatcher
8
+ end
9
+
10
+ let!(:matcher) { Obj.new }
11
+
12
+ # @see http://ja.wikipedia.org/wiki/%E3%83%A1%E3%83%BC%E3%83%AB%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9
13
+ let!(:rfc_emails) { ["Abc.123@example.com",
14
+ "user+mailbox/department=shipping@example.com",
15
+ "!#$\%&'*+-/=?^_`.{|}~@example.com",
16
+ "\"Abc@def\"@example.com",
17
+ "\"Fred Bloggs\"@example.com"]
18
+ # "\"Joe.\\\\Blow\"@example.com" # これは諦め
19
+ }
20
+ describe ".has_rfc_email?" do
21
+ context "正しいEmailの場合" do
22
+ it { rfc_emails.each { |f| matcher.has_rfc_email?(f).should be_true } }
23
+ end
24
+ context "文章中にメールアドレスが含まれている場合" do
25
+ it { matcher.has_rfc_email?("メールアドレスはxxxxx@example.comです").should be_true }
26
+ it { matcher.has_rfc_email?("メールアドレスは\r\nxxxxx@example.comです").should be_true }
27
+ end
28
+ end
29
+
30
+ describe ".pick_rfc_email" do
31
+ context "正しいEmailが1つだけ含まれている場合" do
32
+ subject { matcher.pick_rfc_email("私のメールアドレスは#{rfc_emails[0]}です") }
33
+ its(:size) { should eql 1 }
34
+ its([0]) { should eql rfc_emails[0] }
35
+ end
36
+
37
+ context "正しいEmailが2つ以上含まれている場合" do
38
+ subject { matcher.pick_rfc_email(rfc_emails.join(" デス\r\nよ")) }
39
+ its(:size) { should eql 5 }
40
+ its([0]) { should eql rfc_emails[0] }
41
+ its([1]) { should eql rfc_emails[1] }
42
+ its([2]) { should eql rfc_emails[2] }
43
+ its([3]) { should eql rfc_emails[3] }
44
+ its([4]) { should eql rfc_emails[4] }
45
+ end
46
+
47
+ context "Emailが含まれていない場合" do
48
+ subject { matcher.pick_rfc_email("testtest") }
49
+ its(:size) { should eql 0 }
50
+ end
51
+ end
52
+
53
+ describe ".rfc_email_masking" do
54
+ context "正しいEmailが1つだけ含まれている場合" do
55
+ subject { matcher.rfc_email_masking("私のメールアドレスは#{rfc_emails[0]}です") }
56
+ it { should eql "私のメールアドレスは***です" }
57
+ end
58
+
59
+ context "正しいEmailが2つ以上含まれている場合" do
60
+ subject { matcher.rfc_email_masking(rfc_emails.join(" デス\r\nよ"), "+++") }
61
+ it { should eql (["+++"]*5).join(" デス\r\nよ") }
62
+ end
63
+
64
+ context "Emailが含まれていない場合" do
65
+ subject { matcher.rfc_email_masking("testtest@hoge.com") }
66
+ it { should eql "testtest@hoge.com" }
67
+ end
68
+ end
69
+
70
+ describe ".special_char" do
71
+ subject { matcher.special_char }
72
+ it { should be_kind_of(String) }
73
+ end
74
+
75
+ describe ".quoted_special_char" do
76
+ subject { matcher.quoted_special_char }
77
+ it { should be_kind_of(String) }
78
+ end
79
+
80
+ describe ".unquoted_regexp" do
81
+ subject { matcher.special_char }
82
+ it { should be_kind_of(String) }
83
+ end
84
+
85
+ describe ".quoted_regexp" do
86
+ subject { matcher.quoted_regexp }
87
+ it { should be_kind_of(String) }
88
+ end
89
+
90
+ describe ".domain_regexp" do
91
+ subject { matcher.domain_regexp }
92
+ it { should be_kind_of(String) }
93
+ end
94
+ end
95
+
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe PrivacyMaskTools::Matcher do
5
+ describe PrivacyMaskTools::PhoneMatcher do
6
6
  class Obj
7
- include PrivacyMaskTools::Matcher
7
+ include PrivacyMaskTools::PhoneMatcher
8
8
  end
9
9
 
10
10
  describe "Rubyにおける日本語のテスト" do
@@ -29,7 +29,7 @@ describe PrivacyMaskTools::Matcher do
29
29
  end
30
30
  context "スペースが含まれる場合" do
31
31
  it { matcher.has_mobile_number?("080 7600 0000").should be_true }
32
- it { matcher.has_mobile_number?("080 (7600) 0000").should be_true }
32
+ it { matcher.has_mobile_number?("080  (7600) 0000").should be_true }
33
33
  end
34
34
  context "全角数字が含まれている場合" do
35
35
  it { matcher.has_mobile_number?("08076345678").should be_true }
@@ -52,21 +52,38 @@ describe PrivacyMaskTools::Matcher do
52
52
  describe ".has_jargon_mobile_number?" do
53
53
  context "漢数字・丸付き数字・o等が含まれている場合" do
54
54
  it { matcher.has_jargon_mobile_number?("0⑧0-1②参四-oO十〇").should be_true }
55
+ it { matcher.has_jargon_mobile_number?("〇九O-①②③④-⑤⑥⑦⑧").should be_true }
55
56
  end
56
57
  end
57
58
 
58
59
  describe ".has_phone_number?" do
60
+ context "携帯番号の場合" do
61
+ it { matcher.has_phone_number?("070-0000-0000").should be_false }
62
+ it { matcher.has_phone_number?("080-0000-0000").should be_false }
63
+ it { matcher.has_phone_number?("090-0000-0000").should be_false }
64
+ end
65
+ context "マッチしない場合" do
66
+ context "最後の数値パターンの末尾に数値が含まれている場合" do
67
+ it { matcher.has_phone_number?("(019)000-00000").should be_false }
68
+ it { matcher.has_phone_number?("019000-99999").should be_false }
69
+ end
70
+ context "桁数が不足している場合" do
71
+ it { matcher.has_phone_number?("011-000-000").should be_false }
72
+ end
73
+ context "加入者番号の桁に数値・指定された記号以外が混入している場合" do
74
+ it { matcher.has_phone_number?("011-000<0000>").should be_false }
75
+ it { matcher.has_phone_number?("011-000-a0000").should be_false }
76
+ end
77
+ end
59
78
  context "([00][334466])[-ー()()・  ]*([0-90-9]{4})の場合" do
60
79
  it { matcher.has_phone_number?("03-0000-1234").should be_true }
61
80
  it { matcher.has_phone_number?("04-0000ー1234").should be_true }
62
81
  it { matcher.has_phone_number?("0600000000").should be_true }
63
- it { matcher.has_phone_number?("080-7900-0000").should be_false }
64
82
  end
65
83
  context "([00][1-91-9]{2})[-ー()()・  ]*([0-90-9]{4})の場合" do
66
84
  it { matcher.has_phone_number?("011-000ー0000").should be_true }
67
85
  it { matcher.has_phone_number?("099-999ー0000").should be_true }
68
86
  it { matcher.has_phone_number?("0190000000").should be_true }
69
- it { matcher.has_phone_number?("(019)000-00000").should be_false }
70
87
  end
71
88
  context "([00][1-91-9]{2}[0-90-9])[-ー()()・  ]*([0-90-9]{2}の場合" do
72
89
  it { matcher.has_phone_number?("0110-00-0000").should be_true }
@@ -78,6 +95,11 @@ describe PrivacyMaskTools::Matcher do
78
95
  it { matcher.has_phone_number?("09999ー9ー9999").should be_true }
79
96
  it { matcher.has_phone_number?("0190900000").should be_true }
80
97
  end
98
+ context "IP電話の場合('([00][55][00])[-ー()()・  ]*(0-90-9)')の場合" do
99
+ it { matcher.has_phone_number?("050-0000-0000").should be_true }
100
+ it { matcher.has_phone_number?("05000000000").should be_true }
101
+ it { matcher.has_phone_number?("050(0000)9999").should be_true }
102
+ end
81
103
  end
82
104
 
83
105
  describe ".has_jargon_phone_number?" do
@@ -90,6 +112,10 @@ describe PrivacyMaskTools::Matcher do
90
112
  it { matcher.has_jargon_phone_number?("〇六-弐参oO-弐参oO").should be_true }
91
113
  it { matcher.has_jargon_phone_number?("〇⑥11111111").should be_true }
92
114
  end
115
+ context "IP電話の場合('([00oO〇十][55五⑤][00oO〇十])[-ー()()・  ]*([0-90-9oO①-⑨一-四〇壱弐参]{4})')" do
116
+ it { matcher.has_jargon_phone_number?("o五o-①②③④-0000").should be_true }
117
+ it { matcher.has_jargon_phone_number?("O⑤O-⑤⑥⑦⑧-0000").should be_true }
118
+ end
93
119
  # TODO more test
94
120
  end
95
121
 
@@ -113,5 +139,45 @@ describe PrivacyMaskTools::Matcher do
113
139
  it { matcher.phone_nomber_masking("これが私の番号です\r\n 03・0000・9999", "No").should eql "これが私の番号です\r\n No" }
114
140
  end
115
141
  end
142
+
143
+ describe ".pick_mobile_number" do
144
+ context "携帯番号が1つ含まれる場合" do
145
+ subject { matcher.pick_mobile_number("090-0000-0000です\r\nこれが私の番号です 03・0000・9999") }
146
+ its(:size) { should eql 1 }
147
+ its([0]) { should eql "090-0000-0000" }
148
+ end
149
+ context "携帯番号が2つ以上含まれる場合" do
150
+ subject { matcher.pick_mobile_number("090-0000-0000です\r\nこれが私の番号です 090・0000・9999") }
151
+ its(:size) { should eql 2 }
152
+ its([0]) { should eql "090-0000-0000" }
153
+ its([1]) { should eql "090・0000・9999" }
154
+ end
155
+ context "jargonモードを有効にした場合" do
156
+ subject { matcher.pick_mobile_number("0⑨0-〇①②③-0000です\r\nこれが私の番号です 090・0000・9999", true) }
157
+ its(:size) { should eql 2 }
158
+ its([0]) { should eql "0⑨0-〇①②③-0000" }
159
+ its([1]) { should eql "090・0000・9999" }
160
+ end
161
+ end
162
+
163
+ describe ".pick_phone_number" do
164
+ context "電話番号が1つ含まれる場合" do
165
+ subject { matcher.pick_phone_number("090-0000-0000です\r\nこれが私の番号です 03・0000・9999") }
166
+ its(:size) { should eql 1 }
167
+ its([0]) { should eql "03・0000・9999" }
168
+ end
169
+ context "電話番号が2つ以上含まれる場合" do
170
+ subject { matcher.pick_phone_number("03-0000-0000です\r\nこれが私の番号です 03・0000・9999\r\n030・0000・9999") }
171
+ its(:size) { should eql 2 }
172
+ its([0]) { should eql "03-0000-0000" }
173
+ its([1]) { should eql "03・0000・9999" }
174
+ end
175
+ context "jargonモードを有効にした場合" do
176
+ subject { matcher.pick_phone_number("〇参-0000-0000です\r\nこれが私の番号です 03・0000・9999\r\n030・0000・9999", true) }
177
+ its(:size) { should eql 2 }
178
+ its([0]) { should eql "〇参-0000-0000" }
179
+ its([1]) { should eql "03・0000・9999" }
180
+ end
181
+ end
116
182
  end
117
183
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: privacy_mask_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-20 00:00:00.000000000Z
12
+ date: 2011-08-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &71821410 !ruby/object:Gem::Requirement
16
+ requirement: &70726420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *71821410
24
+ version_requirements: *70726420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tapp
27
- requirement: &71821160 !ruby/object:Gem::Requirement
27
+ requirement: &70726170 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *71821160
35
+ version_requirements: *70726170
36
36
  description: this module can find privacy data from text data. Try PrivacyMaskTools::Base.has_mobile_number?("<Text
37
37
  Data>")
38
38
  email:
@@ -66,11 +66,13 @@ files:
66
66
  - init.rb
67
67
  - lib/privacy_mask_tools.rb
68
68
  - lib/privacy_mask_tools/base.rb
69
- - lib/privacy_mask_tools/matcher.rb
69
+ - lib/privacy_mask_tools/email_matcher.rb
70
+ - lib/privacy_mask_tools/phone_matcher.rb
70
71
  - lib/privacy_mask_tools/version.rb
71
72
  - privacy_mask_tools.gemspec
72
73
  - spec/privacy_mask_tools/base_spec.rb
73
- - spec/privacy_mask_tools/matcher_spec.rb
74
+ - spec/privacy_mask_tools/email_matcher_spec.rb
75
+ - spec/privacy_mask_tools/phone_matcher_spec.rb
74
76
  - spec/spec_helper.rb
75
77
  homepage: https://github.com/namakesugi/privacy_mask_tools
76
78
  licenses: []