sexmachine 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ docs
2
+ pkg
@@ -0,0 +1 @@
1
+ sexmachine
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p392
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
@@ -1,16 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sexmachine (0.0.5)
4
+ sexmachine (0.1.0)
5
5
  unicode_utils (>= 1.3.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- unicode_utils (1.3.0)
10
+ json (1.8.1)
11
+ minitest (5.3.3)
12
+ rake (10.3.1)
13
+ rdoc (4.1.1)
14
+ json (~> 1.4)
15
+ unicode_utils (1.4.0)
11
16
 
12
17
  PLATFORMS
13
18
  ruby
14
19
 
15
20
  DEPENDENCIES
21
+ minitest
22
+ rake
23
+ rdoc
16
24
  sexmachine!
@@ -1,5 +1,5 @@
1
1
  = Sex Machine
2
- This gem uses the underlying data from the program "gender" by Jorg Michael (described {here}[http://www.autohotkey.com/community/viewtopic.php?t=22000]). It's use is pretty straightforward:
2
+ This gem uses the underlying data from the program "gender" by Jorg Michael (described {here}[http://www.autohotkey.com/community/viewtopic.php?t=22000]). Its use is pretty straightforward:
3
3
 
4
4
  >> require 'sexmachine'
5
5
  >> d = SexMachine::Detector.new
data/Rakefile CHANGED
@@ -1,13 +1,18 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ require "bundler/gem_tasks"
3
2
  require 'rdoc/task'
3
+ require 'rake/testtask'
4
4
 
5
- Bundler::GemHelper.install_tasks
5
+ task :default => [:test]
6
6
 
7
- desc "Create documentation"
8
7
  RDoc::Task.new("doc") { |rdoc|
9
8
  rdoc.title = "SexMachine - Gender from first name"
10
9
  rdoc.rdoc_dir = 'docs'
11
10
  rdoc.rdoc_files.include('README.rdoc')
12
11
  rdoc.rdoc_files.include('lib/**/*.rb')
13
12
  }
13
+
14
+ desc "Run all unit tests"
15
+ Rake::TestTask.new("test") { |t|
16
+ t.libs << "lib"
17
+ t.test_files = FileList['test/*.rb']
18
+ }
@@ -9,12 +9,32 @@ module SexMachine
9
9
  :greece, :russia, :belarus, :moldova, :ukraine, :armenia, :azerbaijan, :georgia, :the_stans, :turkey, :arabia, :israel, :china,
10
10
  :india, :japan, :korea, :vietnam, :other_countries ]
11
11
 
12
+ ISO_3166_MAPPING = {
13
+ 'AE' => :arabia, 'AL' => :albania, 'AM' => :armenia, 'AT' => :austria,
14
+ 'AU' => :usa, 'AZ' => :azerbaijan, 'BA' => :bosniaand, 'BE' => :belgium,
15
+ 'BG' => :bulgaria, 'BH' => :arabia, 'BY' => :belarus, 'CA' => :usa,
16
+ 'CH' => :swiss, 'CN' => :china, 'CZ' => :czech_republic, 'DE' => :germany,
17
+ 'DK' => :denmark, 'EE' => :estonia, 'EG' => :arabia, 'ES' => :spain,
18
+ 'FI' => :finland, 'FR' => :france, 'GB' => :great_britain, 'GE' => :georgia,
19
+ 'GR' => :greece, 'HK' => :china, 'HR' => :croatia, 'HU' => :hungary,
20
+ 'IE' => :ireland, 'IL' => :israel, 'IN' => :india, 'IS' => :iceland,
21
+ 'IT' => :italy, 'JP' => :japan, 'KP' => :korea, 'KR' => :korea,
22
+ 'KZ' => :the_stans, 'LT' => :lithuania, 'LU' => :luxembourg, 'LV' => :latvia,
23
+ 'MD' => :moldova, 'ME' => :montenegro, 'MK' => :macedonia, 'MT' => :malta,
24
+ 'NL' => :the_netherlands, 'NO' => :norway, 'PL' => :poland, 'PT' => :portugal,
25
+ 'QA' => :arabia, 'RO' => :romania, 'RS' => :serbia, 'RU' => :russia,
26
+ 'SA' => :arabia, 'SE' => :sweden, 'SI' => :slovenia, 'SK' => :slovakia,
27
+ 'TR' => :turkey, 'TW' => :china, 'UA' => :ukraine, 'US' => :usa,
28
+ 'UZ' => :the_stans, 'VN' => :vietnam
29
+ }
30
+
12
31
  def initialize(opts = {})
13
32
  opts = {
14
33
  :filename => File.expand_path('../data/nam_dict.txt', __FILE__),
15
34
  :case_sensitive => true,
16
35
  :unknown_value => :andy
17
36
  }.merge(opts)
37
+ @filename = opts[:filename]
18
38
  @case_sensitive = opts[:case_sensitive]
19
39
  @unknown_value = opts[:unknown_value]
20
40
  parse opts[:filename]
@@ -29,26 +49,45 @@ module SexMachine
29
49
  }
30
50
  end
31
51
 
52
+ def knows_country?(country)
53
+ COUNTRIES.include?(country) or ISO_3166_MAPPING.include?(country)
54
+ end
55
+
56
+ def name_exists?(name)
57
+ name = UnicodeUtils.downcase(name) unless @case_sensitive
58
+ @names.has_key?(name) ? name : false
59
+ end
60
+
32
61
  def get_gender(name, country = nil)
33
62
  name = UnicodeUtils.downcase(name) unless @case_sensitive
34
63
 
35
- if not @names.has_key?(name)
64
+ if not name_exists?(name)
36
65
  @unknown_value
37
66
  elsif country.nil?
38
67
  most_popular_gender(name) { |country_values|
39
68
  country_values.split("").select { |l| l.strip != "" }.length
40
69
  }
41
70
  elsif COUNTRIES.include?(country)
42
- index = COUNTRIES.index(country)
43
- most_popular_gender(name) { |country_values|
44
- country_values[index].ord
45
- }
71
+ most_popular_gender_in_country(name, country)
72
+ elsif ISO_3166_MAPPING.include?(country)
73
+ most_popular_gender_in_country(name, ISO_3166_MAPPING[country])
46
74
  else
47
75
  raise "No such country: #{country}"
48
76
  end
49
77
  end
50
78
 
79
+ def inspect
80
+ "#<#{self.class.name} filename=\"#{@filename}\" case_sensitive=#{@case_sensitive} unknown_value=#{@unknown_value}>"
81
+ end
82
+
51
83
  private
84
+ def most_popular_gender_in_country(name, country)
85
+ index = COUNTRIES.index(country)
86
+ most_popular_gender(name) { |country_values|
87
+ country_values[index].ord
88
+ }
89
+ end
90
+
52
91
  def eat_name_line(line)
53
92
  return if line.start_with?("#") or line.start_with?("=")
54
93
 
@@ -92,5 +131,4 @@ module SexMachine
92
131
  end
93
132
  end
94
133
  end
95
-
96
134
  end
@@ -1,3 +1,3 @@
1
1
  module SexMachine
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'sexmachine/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sexmachine"
7
+ s.version = SexMachine::VERSION
8
+ s.authors = ["Brian Muller"]
9
+ s.email = ["bamuller@gmail.com"]
10
+ s.description = "Get gender from first name."
11
+ s.summary = "Get gender from first name."
12
+ s.files = `git ls-files`.split($/)
13
+ s.homepage = "https://github.com/bmuller/sexmachine"
14
+ s.require_paths = ["lib"]
15
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.0")
16
+ s.add_dependency('unicode_utils', '>= 1.3.0')
17
+ s.add_development_dependency('minitest')
18
+ s.add_development_dependency("rake")
19
+ s.add_development_dependency("rdoc")
20
+ end
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'sexmachine'
6
+
7
+ class SexMachineTest < MiniTest::Test
8
+ def setup
9
+ @d = SexMachine::Detector.new
10
+ end
11
+
12
+ def test_get_gender
13
+ assert_equal :male, @d.get_gender("Bob")
14
+ assert_equal :female, @d.get_gender("Sally")
15
+ assert_equal :andy, @d.get_gender("Pauley")
16
+ end
17
+
18
+ def test_gender_international
19
+ assert @d.knows_country?(:great_britain)
20
+ assert_equal :female, @d.get_gender("Álfrún")
21
+ end
22
+
23
+ def test_country_specific_preference
24
+ assert_equal :female, @d.get_gender("Jamie")
25
+ assert_equal :mostly_male, @d.get_gender("Jamie", :great_britain) #jamie oliver?
26
+ end
27
+
28
+ def test_case_insensitivity
29
+ d = SexMachine::Detector.new(:case_sensitive => false)
30
+ assert_equal :female, d.get_gender("sally")
31
+ assert_equal :female, d.get_gender("Sally")
32
+ end
33
+
34
+ def test_name_exists
35
+ d = SexMachine::Detector.new(:case_sensitive => false)
36
+ assert d.name_exists?("Sally")
37
+ assert d.name_exists?("Carlos")
38
+ assert d.name_exists?("Rosario")
39
+ end
40
+ end
metadata CHANGED
@@ -1,72 +1,127 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sexmachine
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  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
- date: 2012-11-09 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: unicode_utils
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 1.3.0
24
22
  type: :runtime
25
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
26
78
  description: Get gender from first name.
27
- email: brian.muller@livingsocial.com
79
+ email:
80
+ - bamuller@gmail.com
28
81
  executables: []
29
-
30
82
  extensions: []
31
-
32
83
  extra_rdoc_files: []
33
-
34
- files:
35
- - lib/sexmachine/data/nam_dict.txt
36
- - lib/sexmachine/detector.rb
37
- - lib/sexmachine/version.rb
38
- - lib/sexmachine.rb
84
+ files:
85
+ - .gitignore
86
+ - .ruby-gemset
87
+ - .ruby-version
88
+ - .travis.yml
39
89
  - Gemfile
40
90
  - Gemfile.lock
41
91
  - LICENSE
42
- - Rakefile
43
92
  - README.rdoc
93
+ - Rakefile
94
+ - lib/sexmachine.rb
95
+ - lib/sexmachine/data/nam_dict.txt
96
+ - lib/sexmachine/detector.rb
97
+ - lib/sexmachine/version.rb
98
+ - sexmachine.gemspec
99
+ - test/sexmachine_test.rb
44
100
  homepage: https://github.com/bmuller/sexmachine
45
101
  licenses: []
46
-
47
102
  post_install_message:
48
103
  rdoc_options: []
49
-
50
- require_paths:
104
+ require_paths:
51
105
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
53
107
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
57
111
  version: 1.9.0
58
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
113
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 4014746446329583029
64
121
  requirements: []
65
-
66
- rubyforge_project: sexmachine
67
- rubygems_version: 1.8.24
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.25
68
124
  signing_key:
69
125
  specification_version: 3
70
126
  summary: Get gender from first name.
71
127
  test_files: []
72
-