data_masker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'data_masker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'data_masker'
8
+ spec.version = DataMasker::VERSION
9
+ spec.authors = ['Peak Xu']
10
+ spec.email = ['peak.xu@gmail.com']
11
+
12
+ spec.summary = 'Fast way to mask user data for testing or demos'
13
+ spec.description = 'Mask user data like names in a quick and deterministic'\
14
+ ' way'
15
+ spec.homepage = 'https://github.com/peakxu/data_masker'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.8'
25
+ spec.add_development_dependency 'pry', '~> 0.10.3'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.4.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.35.1'
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'data_masker/version'
2
+ require 'data_masker/masked_name'
3
+
4
+ #
5
+ module DataMasker
6
+ class << self
7
+ attr_accessor :salt # Can be set to seed randomization
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ require 'digest'
2
+
3
+ #
4
+ module DataMasker
5
+ # Mask common names using names from US census
6
+ class MaskedName
7
+ class << self
8
+ def first_names
9
+ return @first_names if @first_names
10
+ file = File.expand_path('../../../data/us_first_names.txt', __FILE__)
11
+ @first_names = File.readlines(file).map(&:strip)
12
+ end
13
+
14
+ def last_names
15
+ return @last_names if @last_names
16
+ file = File.expand_path('../../../data/us_last_names.txt', __FILE__)
17
+ @last_names = File.readlines(file).map(&:strip)
18
+ end
19
+
20
+ def initials
21
+ @initials ||= ('A'..'Z').to_a
22
+ end
23
+ end
24
+
25
+ def initialize(name = nil)
26
+ @hash = Digest::MD5.hexdigest("#{DataMasker.salt}#{name}")
27
+ end
28
+
29
+ def to_s
30
+ "#{first_name} #{initial}. #{last_name}"
31
+ end
32
+
33
+ def first_name
34
+ return @first_name if @first_name
35
+ # First 3 hex digits provide 4096 possibilities, we have 2048 first names
36
+ first_name_idx = @hash[0..2].hex / 2
37
+ @first_name = self.class.first_names[first_name_idx]
38
+ end
39
+
40
+ def initial
41
+ return @initial if @initial
42
+ # Next 2 hex digits provide 256 possibilities, divide by 10 to distribute
43
+ # over 26 initials
44
+ initial_idx = @hash[3..4].hex / 10
45
+ @initial = self.class.initials[initial_idx]
46
+ end
47
+
48
+ def last_name
49
+ return @last_name if @last_name
50
+ # Next 3 hex digits provide 4096 possibilites, we have 4096 last names
51
+ last_name_idx = @hash[5..7].hex
52
+ @last_name = self.class.last_names[last_name_idx]
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ #
2
+ module DataMasker
3
+ VERSION = '0.1.0'
4
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_masker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peak Xu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.4.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.35.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.35.1
83
+ description: Mask user data like names in a quick and deterministic way
84
+ email:
85
+ - peak.xu@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - data/us_first_names.txt
99
+ - data/us_last_names.txt
100
+ - data_masker.gemspec
101
+ - lib/data_masker.rb
102
+ - lib/data_masker/masked_name.rb
103
+ - lib/data_masker/version.rb
104
+ homepage: https://github.com/peakxu/data_masker
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Fast way to mask user data for testing or demos
127
+ test_files: []