gendered 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 213cf78b4e398d842b731504c37c8eca47a9c7f6
4
- data.tar.gz: 7e98e2fdc2ab330f58da7938250d3a54aa6b0192
3
+ metadata.gz: f86b31842ddc95c2113669e6f66a5d99aac816a3
4
+ data.tar.gz: c94175107eea8f35359a3e3ce610c59572847f5e
5
5
  SHA512:
6
- metadata.gz: 74eb2b0daeb45432a588304c21b30be3338a434828e6876501b142a37b159bf5960ab3afcc7c475da87ccf09366b7e410976d5da5fdff19691f86ba1253dbc2a
7
- data.tar.gz: 42d7e26ea68a38ef090e5a230a3dea8b7b6d07a948ea8213249029601f6ba3314808d5edfda2ece6cd52f19831fc782649aa69daa6e3b0e989123f299c34e81e
6
+ metadata.gz: d69366b21df292f59b479a5eba8c16d3055b7de8b457acc968bbf0aa52c7b40057f5e40659d6f5c1334203f2dfb9394226652183cfe41b8240b3ad250ee57582
7
+ data.tar.gz: dc544551f8658804b434b29269d374f6aa5cbd31df8b1dd4027c063bef8667d2d2a099df7eecab15b5070da432f80acd663fa749f1903b18dd242ae22ef78ae8
@@ -1,12 +1,13 @@
1
1
  module Gendered
2
2
  class Guesser
3
3
 
4
- attr_accessor :names
4
+ attr_accessor :names, :country_id
5
5
 
6
- def initialize(values)
6
+ def initialize(values, country_id = nil)
7
7
  raise ArgumentError, "cannot be empty" if Array(values).empty?
8
8
 
9
9
  @names = Array(values)
10
+ @country_id = country_id
10
11
  end
11
12
 
12
13
  def guess!
@@ -34,11 +35,12 @@ module Gendered
34
35
 
35
36
  def url
36
37
  url = "http://api.genderize.io/?"
38
+ url += "country_id=#{country_id}&" if country_id
39
+
37
40
  name_queries = names.collect.with_index do |name, index|
38
41
  "name[#{index}]=#{CGI.escape(name.to_s)}"
39
42
  end
40
43
  url + name_queries.join("&")
41
44
  end
42
-
43
45
  end
44
46
  end
@@ -16,8 +16,8 @@ module Gendered
16
16
  !!@gender
17
17
  end
18
18
 
19
- def guess!
20
- Guesser.new(self).guess!
19
+ def guess!(country_id = nil)
20
+ Guesser.new(self, country_id).guess!
21
21
  gender
22
22
  end
23
23
 
@@ -13,9 +13,9 @@ module Gendered
13
13
  end
14
14
  end
15
15
 
16
- def guess!
16
+ def guess!(country_id = nil)
17
17
  names.each_slice(100).each do |slice|
18
- Guesser.new(slice).guess!
18
+ Guesser.new(slice).guess!(country_id)
19
19
  end
20
20
  names.collect(&:gender)
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module Gendered
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,6 +13,11 @@ module Gendered
13
13
  expect(subject.names).to eq names
14
14
  end
15
15
 
16
+ it "is initialized with country id" do
17
+ guesser = Guesser.new(names, 'us')
18
+ expect(guesser.country_id).to eq 'us'
19
+ end
20
+
16
21
  it "creates the correct url" do
17
22
  expect(subject.url).to eq "http://api.genderize.io/?name[0]=Sean&name[1]=Theresa"
18
23
  end
@@ -13,6 +13,13 @@ module Gendered
13
13
  expect(Guesser).to receive(:new).with(subject.names).and_return(guesser)
14
14
  subject.guess!
15
15
  end
16
+
17
+ it 'guesses correctly with country id' do
18
+ guesser = double(Guesser)
19
+ expect(guesser).to receive(:guess!).with('us')
20
+ expect(Guesser).to receive(:new).with(subject.names).and_return(guesser)
21
+ subject.guess!('us')
22
+ end
16
23
  end
17
24
  context "when the values are strings" do
18
25
  it "sets the names" do
@@ -23,6 +23,12 @@ module Gendered
23
23
  it "returns the gender" do
24
24
  expect(subject.guess!).to eq :male
25
25
  end
26
+
27
+ it 'returns gender by country id' do
28
+ name = Gendered::Name.new('kim')
29
+ expect(name.guess!).to eq :female
30
+ expect(name.guess!('dk')).to eq :male
31
+ end
26
32
  end
27
33
 
28
34
  describe "#gender=" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gendered
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Devine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-28 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.4.5
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Guess the gender of a name.
@@ -124,4 +124,3 @@ test_files:
124
124
  - spec/lib/gendered/name_list_spec.rb
125
125
  - spec/lib/gendered/name_spec.rb
126
126
  - spec/spec_helper.rb
127
- has_rdoc: