sexmachine 0.0.4 → 0.0.5

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.
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sexmachine (0.0.4)
4
+ sexmachine (0.0.5)
5
+ unicode_utils (>= 1.3.0)
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
8
9
  specs:
10
+ unicode_utils (1.3.0)
9
11
 
10
12
  PLATFORMS
11
13
  ruby
@@ -24,7 +24,13 @@ Additionally, you can give preference to specific countries:
24
24
  >> d.get_gender("Jamie", :great_britain)
25
25
  => :mostly_male
26
26
 
27
- If you have an alterative data file, you can pass that in as an optional argument to the Detector.
27
+ If you have an alterative data file, you can pass that in as an optional filename argument to the Detector. Additionally, you can create a detector that is not case sensitive (default *is* to be case sensitive):
28
+
29
+ >> d = SexMachine::Detector.new(:case_sensitive => false)
30
+ >> d.get_gender "sally"
31
+ => :female
32
+ >> d.get_gender "Sally"
33
+ => :female
28
34
 
29
35
  Try to avoid creating many Detectors, as each creation means reading in the data file.
30
36
 
@@ -1,3 +1,5 @@
1
+ require "unicode_utils/downcase"
2
+
1
3
  module SexMachine
2
4
 
3
5
  class Detector
@@ -7,9 +9,13 @@ module SexMachine
7
9
  :greece, :russia, :belarus, :moldova, :ukraine, :armenia, :azerbaijan, :georgia, :the_stans, :turkey, :arabia, :israel, :china,
8
10
  :india, :japan, :korea, :vietnam, :other_countries ]
9
11
 
10
- def initialize(fname=nil)
11
- fname ||= File.expand_path('../data/nam_dict.txt', __FILE__)
12
- parse fname
12
+ def initialize(opts = {})
13
+ opts = {
14
+ :filename => File.expand_path('../data/nam_dict.txt', __FILE__),
15
+ :case_sensitive => true
16
+ }.merge(opts)
17
+ @case_sensitive = opts[:case_sensitive]
18
+ parse opts[:filename]
13
19
  end
14
20
 
15
21
  def parse(fname)
@@ -22,6 +28,8 @@ module SexMachine
22
28
  end
23
29
 
24
30
  def get_gender(name, country = nil)
31
+ name = UnicodeUtils.downcase(name) unless @case_sensitive
32
+
25
33
  if not @names.has_key?(name)
26
34
  :andy
27
35
  elsif country.nil?
@@ -44,13 +52,14 @@ module SexMachine
44
52
 
45
53
  parts = line.split(" ").select { |p| p.strip != "" }
46
54
  country_values = line.slice(30, line.length)
55
+ name = @case_sensitive ? parts[1] : UnicodeUtils.downcase(parts[1])
47
56
 
48
57
  case parts[0]
49
- when "M" then set(parts[1], :male, country_values)
50
- when "1M", "?M" then set(parts[1], :mostly_male, country_values)
51
- when "F" then set(parts[1], :female, country_values)
52
- when "1F", "?F" then set(parts[1], :mostly_female, country_values)
53
- when "?" then set(parts[1], :andy, country_values)
58
+ when "M" then set(name, :male, country_values)
59
+ when "1M", "?M" then set(name, :mostly_male, country_values)
60
+ when "F" then set(name, :female, country_values)
61
+ when "1F", "?F" then set(name, :mostly_female, country_values)
62
+ when "?" then set(name, :andy, country_values)
54
63
  else raise "Not sure what to do with a sex of #{parts[0]}"
55
64
  end
56
65
  end
@@ -1,3 +1,3 @@
1
1
  module SexMachine
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sexmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-25 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-07-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: unicode_utils
16
+ requirement: &70220187561160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70220187561160
14
25
  description: Get gender from first name.
15
26
  email: brian.muller@livingsocial.com
16
27
  executables: []