sexmachine 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -1
- data/lib/sexmachine/detector.rb +16 -14
- data/lib/sexmachine/version.rb +1 -1
- metadata +33 -34
- data/docs/README_rdoc.html +0 -123
- data/docs/SexMachine.html +0 -163
- data/docs/SexMachine/Detector.html +0 -376
- data/docs/created.rid +0 -5
- data/docs/index.html +0 -68
- data/docs/lib/sexmachine/detector_rb.html +0 -52
- data/docs/lib/sexmachine/version_rb.html +0 -52
- data/docs/lib/sexmachine_rb.html +0 -56
- data/docs/rdoc.css +0 -706
data/Rakefile
CHANGED
data/lib/sexmachine/detector.rb
CHANGED
@@ -12,12 +12,14 @@ module SexMachine
|
|
12
12
|
def initialize(opts = {})
|
13
13
|
opts = {
|
14
14
|
:filename => File.expand_path('../data/nam_dict.txt', __FILE__),
|
15
|
-
:case_sensitive => true
|
15
|
+
:case_sensitive => true,
|
16
|
+
:unknown_value => :andy
|
16
17
|
}.merge(opts)
|
17
18
|
@case_sensitive = opts[:case_sensitive]
|
19
|
+
@unknown_value = opts[:unknown_value]
|
18
20
|
parse opts[:filename]
|
19
21
|
end
|
20
|
-
|
22
|
+
|
21
23
|
def parse(fname)
|
22
24
|
@names = {}
|
23
25
|
open(fname, "r:iso8859-1:utf-8") { |f|
|
@@ -26,12 +28,12 @@ module SexMachine
|
|
26
28
|
}
|
27
29
|
}
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
def get_gender(name, country = nil)
|
31
33
|
name = UnicodeUtils.downcase(name) unless @case_sensitive
|
32
34
|
|
33
35
|
if not @names.has_key?(name)
|
34
|
-
|
36
|
+
@unknown_value
|
35
37
|
elsif country.nil?
|
36
38
|
most_popular_gender(name) { |country_values|
|
37
39
|
country_values.split("").select { |l| l.strip != "" }.length
|
@@ -45,28 +47,28 @@ module SexMachine
|
|
45
47
|
raise "No such country: #{country}"
|
46
48
|
end
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
private
|
50
52
|
def eat_name_line(line)
|
51
53
|
return if line.start_with?("#") or line.start_with?("=")
|
52
|
-
|
54
|
+
|
53
55
|
parts = line.split(" ").select { |p| p.strip != "" }
|
54
56
|
country_values = line.slice(30, line.length)
|
55
57
|
name = @case_sensitive ? parts[1] : UnicodeUtils.downcase(parts[1])
|
56
58
|
|
57
59
|
case parts[0]
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
when "M" then set(name, :male, country_values)
|
61
|
+
when "1M", "?M" then set(name, :mostly_male, country_values)
|
62
|
+
when "F" then set(name, :female, country_values)
|
63
|
+
when "1F", "?F" then set(name, :mostly_female, country_values)
|
64
|
+
when "?" then set(name, :andy, country_values)
|
65
|
+
else raise "Not sure what to do with a sex of #{parts[0]}"
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
def most_popular_gender(name)
|
68
|
-
return
|
69
|
-
|
70
|
+
return @unknown_value unless @names.has_key?(name)
|
71
|
+
|
70
72
|
max = 0
|
71
73
|
best = @names[name].keys.first
|
72
74
|
@names[name].each { |gender, country_values|
|
data/lib/sexmachine/version.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sexmachine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.5
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Brian Muller
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2012-11-09 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: unicode_utils
|
16
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
19
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
21
23
|
version: 1.3.0
|
22
24
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *70220187561160
|
25
|
+
version_requirements: *id001
|
25
26
|
description: Get gender from first name.
|
26
27
|
email: brian.muller@livingsocial.com
|
27
28
|
executables: []
|
29
|
+
|
28
30
|
extensions: []
|
31
|
+
|
29
32
|
extra_rdoc_files: []
|
30
|
-
|
33
|
+
|
34
|
+
files:
|
31
35
|
- lib/sexmachine/data/nam_dict.txt
|
32
36
|
- lib/sexmachine/detector.rb
|
33
37
|
- lib/sexmachine/version.rb
|
@@ -37,37 +41,32 @@ files:
|
|
37
41
|
- LICENSE
|
38
42
|
- Rakefile
|
39
43
|
- README.rdoc
|
40
|
-
- docs/created.rid
|
41
|
-
- docs/index.html
|
42
|
-
- docs/lib/sexmachine/detector_rb.html
|
43
|
-
- docs/lib/sexmachine/version_rb.html
|
44
|
-
- docs/lib/sexmachine_rb.html
|
45
|
-
- docs/rdoc.css
|
46
|
-
- docs/README_rdoc.html
|
47
|
-
- docs/SexMachine/Detector.html
|
48
|
-
- docs/SexMachine.html
|
49
44
|
homepage: https://github.com/bmuller/sexmachine
|
50
45
|
licenses: []
|
46
|
+
|
51
47
|
post_install_message:
|
52
48
|
rdoc_options: []
|
53
|
-
|
49
|
+
|
50
|
+
require_paths:
|
54
51
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
53
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
60
57
|
version: 1.9.0
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
59
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
67
64
|
requirements: []
|
65
|
+
|
68
66
|
rubyforge_project: sexmachine
|
69
|
-
rubygems_version: 1.8.
|
67
|
+
rubygems_version: 1.8.24
|
70
68
|
signing_key:
|
71
69
|
specification_version: 3
|
72
70
|
summary: Get gender from first name.
|
73
71
|
test_files: []
|
72
|
+
|
data/docs/README_rdoc.html
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
-
|
5
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
-
<head>
|
7
|
-
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
8
|
-
|
9
|
-
<title>File: README.rdoc [SexMachine - Gender from first name]</title>
|
10
|
-
|
11
|
-
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />
|
12
|
-
|
13
|
-
<script src="./js/jquery.js" type="text/javascript"
|
14
|
-
charset="utf-8"></script>
|
15
|
-
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
16
|
-
charset="utf-8"></script>
|
17
|
-
<script src="./js/quicksearch.js" type="text/javascript"
|
18
|
-
charset="utf-8"></script>
|
19
|
-
<script src="./js/darkfish.js" type="text/javascript"
|
20
|
-
charset="utf-8"></script>
|
21
|
-
</head>
|
22
|
-
|
23
|
-
<body class="file">
|
24
|
-
<div id="metadata">
|
25
|
-
<div id="home-metadata">
|
26
|
-
<div id="home-section" class="section">
|
27
|
-
<h3 class="section-header">
|
28
|
-
<a href="./index.html">Home</a>
|
29
|
-
<a href="./index.html#classes">Classes</a>
|
30
|
-
<a href="./index.html#methods">Methods</a>
|
31
|
-
</h3>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="project-metadata">
|
36
|
-
|
37
|
-
|
38
|
-
<div id="fileindex-section" class="section project-section">
|
39
|
-
<h3 class="section-header">Files</h3>
|
40
|
-
<ul>
|
41
|
-
|
42
|
-
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
43
|
-
|
44
|
-
</ul>
|
45
|
-
</div>
|
46
|
-
|
47
|
-
|
48
|
-
<div id="classindex-section" class="section project-section">
|
49
|
-
<h3 class="section-header">Class Index
|
50
|
-
<span class="search-toggle"><img src="./images/find.png"
|
51
|
-
height="16" width="16" alt="[+]"
|
52
|
-
title="show/hide quicksearch" /></span></h3>
|
53
|
-
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
54
|
-
<fieldset>
|
55
|
-
<legend>Quicksearch</legend>
|
56
|
-
<input type="text" name="quicksearch" value=""
|
57
|
-
class="quicksearch-field" />
|
58
|
-
</fieldset>
|
59
|
-
</form>
|
60
|
-
|
61
|
-
<ul class="link-list">
|
62
|
-
|
63
|
-
<li><a href="./SexMachine.html">SexMachine</a></li>
|
64
|
-
|
65
|
-
<li><a href="./SexMachine/Detector.html">SexMachine::Detector</a></li>
|
66
|
-
|
67
|
-
</ul>
|
68
|
-
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
69
|
-
</div>
|
70
|
-
|
71
|
-
|
72
|
-
</div>
|
73
|
-
</div>
|
74
|
-
|
75
|
-
<div id="documentation">
|
76
|
-
<h1>Sex Machine</h1>
|
77
|
-
<p>
|
78
|
-
This gem uses the underlying data from the program “gender” by
|
79
|
-
Jorg Michael (described <a
|
80
|
-
href="http://www.autohotkey.com/community/viewtopic.php?t=22000">here</a>).
|
81
|
-
It’s use is pretty straightforward:
|
82
|
-
</p>
|
83
|
-
<pre>
|
84
|
-
>> require 'sexmachine'
|
85
|
-
>> d = Detector.new
|
86
|
-
>> d.get_gender("Bob")
|
87
|
-
:male
|
88
|
-
>> d.get_gender("Sally")
|
89
|
-
:female
|
90
|
-
>> d.get_gender("Pauley") # should be androgynous
|
91
|
-
:andy
|
92
|
-
</pre>
|
93
|
-
<p>
|
94
|
-
I18N is fully supported:
|
95
|
-
</p>
|
96
|
-
<pre>
|
97
|
-
>> d.get_gender("�lfr�n")
|
98
|
-
:female
|
99
|
-
</pre>
|
100
|
-
<p>
|
101
|
-
If you have an alterative data file, you can pass that in as an optional
|
102
|
-
argument to the Detector.
|
103
|
-
</p>
|
104
|
-
<p>
|
105
|
-
Try to avoid creating many Detectors, as each creation means reading in the
|
106
|
-
data file.
|
107
|
-
</p>
|
108
|
-
<h1>Licenses</h1>
|
109
|
-
<p>
|
110
|
-
The genderator code is distributed under the GPLv3. The data file
|
111
|
-
nam_dict.txt is released under the GNU Free Documentation License.
|
112
|
-
</p>
|
113
|
-
|
114
|
-
</div>
|
115
|
-
|
116
|
-
<div id="validator-badges">
|
117
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
118
|
-
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
119
|
-
Rdoc Generator</a> 1.1.6</small>.</p>
|
120
|
-
</div>
|
121
|
-
</body>
|
122
|
-
</html>
|
123
|
-
|
data/docs/SexMachine.html
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
-
<head>
|
6
|
-
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
-
|
8
|
-
<title>Module: SexMachine</title>
|
9
|
-
|
10
|
-
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
|
11
|
-
|
12
|
-
<script src="./js/jquery.js" type="text/javascript"
|
13
|
-
charset="utf-8"></script>
|
14
|
-
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
15
|
-
charset="utf-8"></script>
|
16
|
-
<script src="./js/quicksearch.js" type="text/javascript"
|
17
|
-
charset="utf-8"></script>
|
18
|
-
<script src="./js/darkfish.js" type="text/javascript"
|
19
|
-
charset="utf-8"></script>
|
20
|
-
|
21
|
-
</head>
|
22
|
-
<body class="module">
|
23
|
-
|
24
|
-
<div id="metadata">
|
25
|
-
<div id="home-metadata">
|
26
|
-
<div id="home-section" class="section">
|
27
|
-
<h3 class="section-header">
|
28
|
-
<a href="./index.html">Home</a>
|
29
|
-
<a href="./index.html#classes">Classes</a>
|
30
|
-
<a href="./index.html#methods">Methods</a>
|
31
|
-
</h3>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="file-metadata">
|
36
|
-
<div id="file-list-section" class="section">
|
37
|
-
<h3 class="section-header">In Files</h3>
|
38
|
-
<div class="section-body">
|
39
|
-
<ul>
|
40
|
-
|
41
|
-
<li><a href="./lib/sexmachine/detector_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
-
class="thickbox" title="lib/sexmachine/detector.rb">lib/sexmachine/detector.rb</a></li>
|
43
|
-
|
44
|
-
<li><a href="./lib/sexmachine/version_rb.html?TB_iframe=true&height=550&width=785"
|
45
|
-
class="thickbox" title="lib/sexmachine/version.rb">lib/sexmachine/version.rb</a></li>
|
46
|
-
|
47
|
-
</ul>
|
48
|
-
</div>
|
49
|
-
</div>
|
50
|
-
|
51
|
-
|
52
|
-
</div>
|
53
|
-
|
54
|
-
<div id="class-metadata">
|
55
|
-
|
56
|
-
<!-- Parent Class -->
|
57
|
-
|
58
|
-
|
59
|
-
<!-- Namespace Contents -->
|
60
|
-
|
61
|
-
<div id="namespace-list-section" class="section">
|
62
|
-
<h3 class="section-header">Namespace</h3>
|
63
|
-
<ul class="link-list">
|
64
|
-
|
65
|
-
<li><span class="type">CLASS</span> <a href="SexMachine/Detector.html">SexMachine::Detector</a></li>
|
66
|
-
|
67
|
-
</ul>
|
68
|
-
</div>
|
69
|
-
|
70
|
-
|
71
|
-
<!-- Method Quickref -->
|
72
|
-
|
73
|
-
|
74
|
-
<!-- Included Modules -->
|
75
|
-
|
76
|
-
</div>
|
77
|
-
|
78
|
-
<div id="project-metadata">
|
79
|
-
|
80
|
-
|
81
|
-
<div id="fileindex-section" class="section project-section">
|
82
|
-
<h3 class="section-header">Files</h3>
|
83
|
-
<ul>
|
84
|
-
|
85
|
-
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
86
|
-
|
87
|
-
</ul>
|
88
|
-
</div>
|
89
|
-
|
90
|
-
|
91
|
-
<div id="classindex-section" class="section project-section">
|
92
|
-
<h3 class="section-header">Class Index
|
93
|
-
<span class="search-toggle"><img src="./images/find.png"
|
94
|
-
height="16" width="16" alt="[+]"
|
95
|
-
title="show/hide quicksearch" /></span></h3>
|
96
|
-
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
97
|
-
<fieldset>
|
98
|
-
<legend>Quicksearch</legend>
|
99
|
-
<input type="text" name="quicksearch" value=""
|
100
|
-
class="quicksearch-field" />
|
101
|
-
</fieldset>
|
102
|
-
</form>
|
103
|
-
|
104
|
-
<ul class="link-list">
|
105
|
-
|
106
|
-
<li><a href="./SexMachine.html">SexMachine</a></li>
|
107
|
-
|
108
|
-
<li><a href="./SexMachine/Detector.html">SexMachine::Detector</a></li>
|
109
|
-
|
110
|
-
</ul>
|
111
|
-
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
112
|
-
</div>
|
113
|
-
|
114
|
-
|
115
|
-
</div>
|
116
|
-
</div>
|
117
|
-
|
118
|
-
<div id="documentation">
|
119
|
-
<h1 class="module">SexMachine</h1>
|
120
|
-
|
121
|
-
<div id="description">
|
122
|
-
|
123
|
-
</div>
|
124
|
-
|
125
|
-
<!-- Constants -->
|
126
|
-
|
127
|
-
<div id="constants-list" class="section">
|
128
|
-
<h3 class="section-header">Constants</h3>
|
129
|
-
<dl>
|
130
|
-
|
131
|
-
<dt><a name="VERSION">VERSION</a></dt>
|
132
|
-
|
133
|
-
<dd class="description"></dd>
|
134
|
-
|
135
|
-
|
136
|
-
</dl>
|
137
|
-
</div>
|
138
|
-
|
139
|
-
|
140
|
-
<!-- Attributes -->
|
141
|
-
|
142
|
-
|
143
|
-
<!-- Methods -->
|
144
|
-
|
145
|
-
|
146
|
-
</div>
|
147
|
-
|
148
|
-
|
149
|
-
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
150
|
-
|
151
|
-
<p>Disabled; run with --debug to generate this.</p>
|
152
|
-
|
153
|
-
</div>
|
154
|
-
|
155
|
-
<div id="validator-badges">
|
156
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
157
|
-
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
158
|
-
Rdoc Generator</a> 1.1.6</small>.</p>
|
159
|
-
</div>
|
160
|
-
|
161
|
-
</body>
|
162
|
-
</html>
|
163
|
-
|