anonymizer 0.0.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.
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ test/*
@@ -0,0 +1,13 @@
1
+ anonymizer.gemspec
2
+ bin/anonymize_data.rb
3
+ lib/anonymizer.rb
4
+ Manifest
5
+ Rakefile
6
+ README.rdoc
7
+ test/out_2/0/ddd.txt
8
+ test/out_2/1.txt
9
+ test/out_2/2/bbb.txt
10
+ test/out_2/3/ccc.txt
11
+ test/out_2/4/eee.txt
12
+ test/out_2/5/aaa.txt
13
+ test/out_2/keymap.csv
File without changes
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "anonymizer"
8
+ gemspec.summary = "Anonymizes a collection of files and/or directories for interrater reliabiliy analyses and the like."
9
+ gemspec.description = "Anonymizes a collection of files and/or directories for interrater reliabiliy analyses and the like."
10
+ gemspec.email = "kk4@medicine.wisc.edu"
11
+ gemspec.homepage = "http://github.com/brainmap/anonymizer"
12
+ gemspec.authors = ["Kristopher J. Kosmatka"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+
20
+
21
+
22
+
23
+ #Echoe.new('anonymizer', '0.1.0') do |p|
24
+ # p.description = "Anonymizes a collection of files and/or directories for interrater reliabiliy analyses and the like."
25
+ # p.url = "http://github.com/kjkosmatka/anonymizer"
26
+ # p.author = "Kristopher J. Kosmatka"
27
+ # p.email = "kk4@medicine.wisc.edu"
28
+ # p.ignore_pattern = ["test/out*"]
29
+ # p.development_dependencies = []
30
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
Binary file
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{anonymizer}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kristopher J. Kosmatka"]
12
+ s.date = %q{2009-12-10}
13
+ s.default_executable = %q{anonymize_data.rb}
14
+ s.description = %q{Anonymizes a collection of files and/or directories for interrater reliabiliy analyses and the like.}
15
+ s.email = %q{kk4@medicine.wisc.edu}
16
+ s.executables = ["anonymize_data.rb"]
17
+ s.extra_rdoc_files = [
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "Manifest",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "anonymizer-0.1.0.gem",
27
+ "anonymizer.gemspec",
28
+ "bin/anonymize_data.rb",
29
+ "doc/classes/Anonymizer.html",
30
+ "doc/classes/Anonymizer.src/M000003.html",
31
+ "doc/classes/Anonymizer.src/M000004.html",
32
+ "doc/classes/Anonymizer.src/M000005.html",
33
+ "doc/classes/Array.html",
34
+ "doc/classes/Array.src/M000001.html",
35
+ "doc/classes/Array.src/M000002.html",
36
+ "doc/created.rid",
37
+ "doc/files/bin/anonymize_data_rb.html",
38
+ "doc/files/lib/anonymizer_rb.html",
39
+ "doc/fr_class_index.html",
40
+ "doc/fr_file_index.html",
41
+ "doc/fr_method_index.html",
42
+ "doc/index.html",
43
+ "doc/rdoc-style.css",
44
+ "lib/anonymizer.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/brainmap/anonymizer}
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = %q{1.3.5}
50
+ s.summary = %q{Anonymizes a collection of files and/or directories for interrater reliabiliy analyses and the like.}
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
+
4
+ require 'optparse'
5
+ require 'anonymizer'
6
+
7
+ options = Hash.new
8
+ options[:collection] = Array.new
9
+ options[:options_for_record_to] = Hash.new
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: anonymize_data.rb [options]"
13
+
14
+ opts.on("-d", "--destination <directory>", "Destination directory in which anonymized data should be save") do |d|
15
+ options[:destination] = d
16
+ end
17
+ opts.on("-c", '--collection "<list>"', "A collection of files and/or directories to anonymize, seperate with spaces. Quotes are necessary.") do |c|
18
+ options[:collection] += c.split
19
+ end
20
+ opts.on("-g", '--glob "<pattern>"', "Use a shell globbing pattern to select your collection. Quotes are neccessary.") do |g|
21
+ options[:collection] += Dir.glob(g)
22
+ end
23
+ opts.on("--include-csv","Write a csv formatted keymap file in addition to the yaml file.") do |i|
24
+ options[:options_for_record_to][:include_csv] = true
25
+ end
26
+ opts.on("-k","--keymap-name <basename>","Use an alternative file basename (i.e. without extension) for the keymap file.") do |k|
27
+ options[:options_for_record_to][:keymap_name] = k
28
+ end
29
+ end.parse!
30
+
31
+
32
+
33
+ raise(IndexError, "No items specified to anonymize. Check your glob pattern or explicitly list your items using -c.") if options[:collection].empty?
34
+
35
+ puts "Anonymizing:"
36
+ options[:collection].each do |i|
37
+ puts "\t#{i}"
38
+ end
39
+ puts "To:"
40
+ puts "\t#{options[:destination]}"
41
+
42
+ begin
43
+ a = Anonymizer.new(options[:collection])
44
+ a.record_to(options[:destination], options[:options_for_record_to])
45
+ rescue
46
+ puts "There was an unknown problem with anonymization. Sorry."
47
+ exit 1
48
+ end
49
+
50
+ puts "+++ Successfully Anonymized. +++\n"
51
+ exit 0
@@ -0,0 +1,227 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Anonymizer</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Anonymizer</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/anonymizer_rb.html">
59
+ lib/anonymizer.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000004">anonymize</a>&nbsp;&nbsp;
90
+ <a href="#M000003">new</a>&nbsp;&nbsp;
91
+ <a href="#M000005">record_to</a>&nbsp;&nbsp;
92
+ </div>
93
+ </div>
94
+
95
+ </div>
96
+
97
+
98
+ <!-- if includes -->
99
+
100
+ <div id="section">
101
+
102
+
103
+
104
+
105
+
106
+ <div id="attribute-list">
107
+ <h3 class="section-bar">Attributes</h3>
108
+
109
+ <div class="name-list">
110
+ <table>
111
+ <tr class="top-aligned-row context-row">
112
+ <td class="context-item-name">anonymizations</td>
113
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
114
+ <td class="context-item-desc">
115
+ a hash, the keys are the original filepaths, the values are the
116
+ corresponding anonymized names
117
+
118
+ </td>
119
+ </tr>
120
+ <tr class="top-aligned-row context-row">
121
+ <td class="context-item-name">destination_dir</td>
122
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
123
+ <td class="context-item-desc">
124
+ a string, the directory to which all of the anoymizations and the key
125
+ should be copied
126
+
127
+ </td>
128
+ </tr>
129
+ <tr class="top-aligned-row context-row">
130
+ <td class="context-item-name">filepaths</td>
131
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
132
+ <td class="context-item-desc">
133
+ an array of strings, the paths to the items to be anonymized
134
+
135
+ </td>
136
+ </tr>
137
+ </table>
138
+ </div>
139
+ </div>
140
+
141
+
142
+
143
+ <!-- if method_list -->
144
+ <div id="methods">
145
+ <h3 class="section-bar">Public Class methods</h3>
146
+
147
+ <div id="method-M000003" class="method-detail">
148
+ <a name="M000003"></a>
149
+
150
+ <div class="method-heading">
151
+ <a href="Anonymizer.src/M000003.html" target="Code" class="method-signature"
152
+ onclick="popupCode('Anonymizer.src/M000003.html');return false;">
153
+ <span class="method-name">new</span><span class="method-args">(filepaths)</span>
154
+ </a>
155
+ </div>
156
+
157
+ <div class="method-description">
158
+ <p>
159
+ Creates a <a href="Anonymizer.html#M000003">new</a> instance with an array
160
+ of filepaths (strings) A <a href="Anonymizer.html#M000003">new</a> set of
161
+ anaonymizations will be created automatically at initialization. If you
162
+ want to reshuffle the anonymizations you can call <a
163
+ href="Anonymizer.html#M000004">anonymize</a> at any time afterward.
164
+ </p>
165
+ </div>
166
+ </div>
167
+
168
+ <h3 class="section-bar">Public Instance methods</h3>
169
+
170
+ <div id="method-M000004" class="method-detail">
171
+ <a name="M000004"></a>
172
+
173
+ <div class="method-heading">
174
+ <a href="Anonymizer.src/M000004.html" target="Code" class="method-signature"
175
+ onclick="popupCode('Anonymizer.src/M000004.html');return false;">
176
+ <span class="method-name">anonymize</span><span class="method-args">()</span>
177
+ </a>
178
+ </div>
179
+
180
+ <div class="method-description">
181
+ <p>
182
+ Reshuffles the anonymized names
183
+ </p>
184
+ </div>
185
+ </div>
186
+
187
+ <div id="method-M000005" class="method-detail">
188
+ <a name="M000005"></a>
189
+
190
+ <div class="method-heading">
191
+ <a href="Anonymizer.src/M000005.html" target="Code" class="method-signature"
192
+ onclick="popupCode('Anonymizer.src/M000005.html');return false;">
193
+ <span class="method-name">record_to</span><span class="method-args">(destination_dir, options = {})</span>
194
+ </a>
195
+ </div>
196
+
197
+ <div class="method-description">
198
+ <p>
199
+ Copies the collection of files/directories to the destination directory
200
+ using the current anonymized names. Records the anonymizations in a
201
+ keymap.yml file.
202
+ </p>
203
+ <h3>Options</h3>
204
+ <p>
205
+ :inclue_csv =&gt; true &#8212; writes the csv format keymap in addition to
206
+ the yaml
207
+ </p>
208
+ <p>
209
+ :keymap_name =&gt; &quot;basename&quot; &#8212; uses an alternate file
210
+ basename for the keymap files (the default is &quot;keymap&quot;)
211
+ </p>
212
+ </div>
213
+ </div>
214
+
215
+
216
+ </div>
217
+
218
+
219
+ </div>
220
+
221
+
222
+ <div id="validator-badges">
223
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
224
+ </div>
225
+
226
+ </body>
227
+ </html>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (Anonymizer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/anonymizer.rb, line 15</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">filepaths</span>)
15
+ <span class="ruby-ivar">@filepaths</span> = <span class="ruby-identifier">filepaths</span>
16
+ <span class="ruby-ivar">@anonymizations</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
17
+ <span class="ruby-identifier">anonymize</span>
18
+ <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>anonymize (Anonymizer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/anonymizer.rb, line 22</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">anonymize</span>
15
+ <span class="ruby-identifier">keys</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@filepaths</span>)
16
+ <span class="ruby-identifier">idx</span> = <span class="ruby-value">0</span>
17
+ <span class="ruby-identifier">ndigits</span> = (<span class="ruby-constant">Math</span>.<span class="ruby-identifier">log10</span>(<span class="ruby-ivar">@filepaths</span>.<span class="ruby-identifier">length</span>)<span class="ruby-operator">+</span><span class="ruby-value">1</span>).<span class="ruby-identifier">floor</span>
18
+ <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">empty?</span>
19
+ <span class="ruby-ivar">@anonymizations</span>[<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">pick!</span>] = <span class="ruby-node">&quot;%0#{ndigits}d&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">idx</span>
20
+ <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
21
+ <span class="ruby-keyword kw">end</span>
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>record_to (Anonymizer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/anonymizer.rb, line 40</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">record_to</span>(<span class="ruby-identifier">destination_dir</span>, <span class="ruby-identifier">options</span> = {})
15
+ <span class="ruby-identifier">raise</span>(<span class="ruby-constant">IOError</span>, <span class="ruby-value str">&quot;Destination directory not found.&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">destination_dir</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">destination_dir</span>)
16
+ <span class="ruby-ivar">@anonymizations</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">orig</span>, <span class="ruby-identifier">anon</span><span class="ruby-operator">|</span>
17
+ <span class="ruby-identifier">copy_directory_or_file</span>(<span class="ruby-identifier">orig</span>, <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">destination_dir</span>, <span class="ruby-identifier">anon</span>))
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-identifier">keymap_filename</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:keymap_name</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;keymap&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:keymap_name</span>]
20
+ <span class="ruby-identifier">write_yml</span>(<span class="ruby-identifier">destination_dir</span>, <span class="ruby-identifier">keymap_filename</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.yml'</span>)
21
+ <span class="ruby-identifier">write_csv</span>(<span class="ruby-identifier">destination_dir</span>, <span class="ruby-identifier">keymap_filename</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.csv'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include_csv</span>]
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>