anon 0.0.1 → 0.0.2
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/lib/anon.rb +5 -0
- data/lib/anon/base.rb +8 -3
- data/lib/anon/cli.rb +6 -0
- data/lib/anon/csv.rb +6 -1
- data/lib/anon/csv/columns.rb +8 -0
- data/lib/anon/text.rb +7 -4
- data/spec/spec_helper.rb +2 -2
- metadata +41 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b2f17f2051079e45100d331e070bd5b22be37f
|
4
|
+
data.tar.gz: 973464a56e3a81b49a90d5f5af2b4b2b23577331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e57175215f6cfd7d35d202a04d3ac3ca54e2e5b1fdd5728f0256195678f541999801d9d2cb306aeaf1398788796ab0e56658936b353fcf719c2f569da26866
|
7
|
+
data.tar.gz: 02bc47de8761b52b902e3996e00ab3890c1b56f999f71579e2ef3ca868e69aa5dbb040d4b66183abac1cf690e188c17d5eb921433c7e24861b2cd5f9e0acd1b9
|
data/lib/anon.rb
CHANGED
data/lib/anon/base.rb
CHANGED
@@ -3,12 +3,15 @@
|
|
3
3
|
require 'time_difference'
|
4
4
|
|
5
5
|
module Anon
|
6
|
-
# Anonymiser base class
|
6
|
+
# Anonymiser base class anonymiser implimentations should inherit from
|
7
7
|
class Base
|
8
8
|
|
9
9
|
# Performs anonymisation
|
10
|
-
|
11
|
-
|
10
|
+
# @param input [IO, gets] the input stream
|
11
|
+
# @param output [IO, puts] the output stream
|
12
|
+
# @param args [*] class specific options
|
13
|
+
def self.anonymise!(input, output, *args)
|
14
|
+
new(input, output, *args).anonymise!
|
12
15
|
end
|
13
16
|
|
14
17
|
protected
|
@@ -18,6 +21,8 @@ module Anon
|
|
18
21
|
#
|
19
22
|
# The same personal e-mail will be replaced
|
20
23
|
# with the same anonymous e-mail.
|
24
|
+
# @param personal_email [String]
|
25
|
+
# @return [String] anonomised email
|
21
26
|
def anonymous_email(personal_email)
|
22
27
|
@anonymised_emails ||= {}
|
23
28
|
|
data/lib/anon/cli.rb
CHANGED
@@ -24,6 +24,10 @@ e.g. 0,1,5 or email-address,other_email, guesses based on header if ommited'
|
|
24
24
|
default: true,
|
25
25
|
desc: 'if the csv file to be processed has a header row'
|
26
26
|
|
27
|
+
# The cli command to launch the CSV anonymiser
|
28
|
+
# Input and output may be set to filepaths, or default to stdin and out
|
29
|
+
# The columns to be anonymised can be set, or we default to a detection stratergy if there is a header row
|
30
|
+
# Optionly we can choose to process files without a header row, but then columns must be set
|
27
31
|
def csv
|
28
32
|
require 'anon/csv'
|
29
33
|
Anon::CSV.anonymise!(input, output, options[:columns], options[:header])
|
@@ -39,6 +43,8 @@ e.g. 0,1,5 or email-address,other_email, guesses based on header if ommited'
|
|
39
43
|
aliases: [:o],
|
40
44
|
desc: 'output filename write to, writes to STDOUT if ommited'
|
41
45
|
|
46
|
+
# The cli command to launch the Text anonymiser
|
47
|
+
# Input and output may be set to filepaths, or default to stdin and out
|
42
48
|
def text
|
43
49
|
require 'anon/text'
|
44
50
|
Anon::Text.anonymise!(input, output)
|
data/lib/anon/csv.rb
CHANGED
@@ -5,8 +5,13 @@ require 'anon/csv/columns'
|
|
5
5
|
require 'csv'
|
6
6
|
|
7
7
|
module Anon
|
8
|
-
# Replaces the contents of a set of columns with anonymous e-mails.
|
8
|
+
# Replaces the contents of a set of columns in a CSV stream with anonymous e-mails.
|
9
9
|
class CSV < Base
|
10
|
+
# Returns a new instance of the CSV anonymiser
|
11
|
+
# @param input [IO, #gets] the stream to read from
|
12
|
+
# @param output [IO, #puts] the stream to write to
|
13
|
+
# @param columns_to_anonymise [String] a comma seperated list of columns to anonymise, if nil we guess
|
14
|
+
# @param has_header [Boolean] defaults to true
|
10
15
|
def initialize(input, output, columns_to_anonymise, has_header = true)
|
11
16
|
@input = input
|
12
17
|
@output = output
|
data/lib/anon/csv/columns.rb
CHANGED
@@ -2,11 +2,19 @@ require 'anon/base'
|
|
2
2
|
|
3
3
|
module Anon
|
4
4
|
class CSV < Base
|
5
|
+
# Encapsulates the logic required to choose and format the list
|
6
|
+
# of columns to be anonomised
|
5
7
|
class Columns
|
8
|
+
# Initialzes a new instance of Columns
|
9
|
+
# @param columns [String] the columns to be anonomised, comma seperated may be names or indexes
|
10
|
+
# @param headers [Array<String>] the full list of headers
|
6
11
|
def initialize(columns, headers)
|
7
12
|
@columns, @headers = columns, headers
|
8
13
|
end
|
9
14
|
|
15
|
+
# Returns the columns that should be anonomised, if the object was initialized without a
|
16
|
+
# predefined list of columns then returns a guess based on the list of headers.
|
17
|
+
# @return [Array<String,Integer>] the columns to be anonomised, indexes are returned as Integer
|
10
18
|
def to_anonymise
|
11
19
|
@_to_anonymise ||= indexes || columns || best_guess
|
12
20
|
end
|
data/lib/anon/text.rb
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
require 'anon/base'
|
4
4
|
|
5
5
|
module Anon
|
6
|
-
# Anonymises any detected e-mail address in a text
|
6
|
+
# Anonymises any detected e-mail address in a text stream
|
7
7
|
class Text < Base
|
8
8
|
# From the email regex research: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
|
9
9
|
# Authors: James Watts and Francisco Jose Martin Moreno
|
10
10
|
EMAIL_REGEX = /([\w\!\#\z\%\&\'\*\+\-\/\=\?\\A\`{\|\}\~]+\.)*[\w\+-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i # rubocop:disable Metrics/LineLength
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# Returns a new instance of the Text anonymiser
|
13
|
+
# @param input [IO, #gets] the stream to read from
|
14
|
+
# @param output [IO, #puts] the stream to write to
|
15
|
+
def initialize(input, output)
|
16
|
+
@input = input
|
17
|
+
@output = output
|
15
18
|
end
|
16
19
|
|
17
20
|
# Anonymises any e-mail addresses found in the text
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reevoo Engineering
|
@@ -14,86 +14,100 @@ dependencies:
|
|
14
14
|
name: time_difference
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.19'
|
34
34
|
type: :runtime
|
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: '0'
|
40
|
+
version: '0.19'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3'
|
47
|
+
version: '3.2'
|
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: '3'
|
54
|
+
version: '3.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.9'
|
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: '0'
|
68
|
+
version: '0.9'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: reevoocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '0.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '0.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '10.4'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '10.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
97
111
|
description: Replaces personal data with fake data
|
98
112
|
email: developers@reevoo.com
|
99
113
|
executables:
|
@@ -126,7 +140,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
140
|
requirements:
|
127
141
|
- - ">="
|
128
142
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
143
|
+
version: '1.9'
|
144
|
+
- - "<"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '3.0'
|
130
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
148
|
requirements:
|
132
149
|
- - ">="
|