gendered 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f5859ca1d1852db42a01dd6bebff96919f330de
4
+ data.tar.gz: a140d18f8c36eb7a57c96442de2ab59e1c21daf9
5
+ SHA512:
6
+ metadata.gz: a9b94c3fe3227f97963dd2bc391a27d8d4cf51de5d621c0635e56666e30c1a115bf51c6f5f3e18a2c8e8f42c83fb6b7a183362a19085ae0ab73aee94e990f499
7
+ data.tar.gz: 579f61a222de993b23679c4aee149892840040d45f91fbb9852dee8b7a5efa30b893e15699450535f62f0799fc16c3ea9a235dcde595754584fd27134f608f9d
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_BIN: exec
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.yardoc
2
+ /Gemfile.lock
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.so
10
+ *.o
11
+ *.a
12
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gendered.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sean Devine
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Gendered
2
+
3
+ **THIS LIBRARY IS STILL IN DEVELOPMENT.**
4
+
5
+ Guess the gender of a name with the help of the [genderize.io](http://genderize.io).
6
+
7
+ ```bash
8
+ gem install gendered
9
+ ```
10
+
11
+ You can guess one name at a time...
12
+ ```ruby
13
+ > require 'gendered'
14
+ > name = Gendered::Name.new("Sean")
15
+ > name.gender
16
+ > :not_guessed
17
+ > name.guess!
18
+ => :male
19
+ > name.male?
20
+ => true
21
+ > name.female?
22
+ => false
23
+ > name.probability
24
+ => "0.99E0"
25
+ > name.sample_size
26
+ => 967
27
+ ```
28
+
29
+ Or batch up a list of names (which sends only one request to the API)...
30
+ ```ruby
31
+ > require 'gendered'
32
+ > name_list = Gendered::NameList.new(["Sean","Theresa"])
33
+ > name_list.guess!
34
+ => [:male, :female]
35
+ > name_list.collect { |name| name.male? }
36
+ => [true, false]
37
+ > name_list.collect { |name| name.female? }
38
+ => [false, true]
39
+ > name_list.collect { |name| name.probability.to_f }
40
+ => [0.99, 1.0]
41
+ > name_list.collect { |name| name.sample_size }
42
+ => [967, 370]
43
+ > name_list["Sean"].gender
44
+ => :male
45
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/exec/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
data/exec/htmldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
data/exec/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/exec/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/exec/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/gendered.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gendered/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gendered"
8
+ spec.version = Gendered::VERSION
9
+ spec.authors = ["Sean Devine"]
10
+ spec.email = ["barelyknown@icloud.com"]
11
+ spec.summary = "Guess the gender of a name."
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "http", ">= 0.6.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
data/lib/gendered.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'bigdecimal'
2
+
3
+ require "http"
4
+
5
+ require "gendered/version"
6
+ require "gendered/name"
7
+ require "gendered/name_list"
8
+ require "gendered/guesser"
9
+
10
+ module Gendered
11
+
12
+ end
@@ -0,0 +1,42 @@
1
+ module Gendered
2
+ class Guesser
3
+
4
+ attr_accessor :names
5
+
6
+ def initialize(values)
7
+ raise ArgumentError, "cannot be empty" if Array(values).empty?
8
+
9
+ @names = Array(values)
10
+ end
11
+
12
+ def guess!
13
+ response = HTTP.get(url)
14
+ case response.code
15
+ when 200
16
+ @names = JSON.parse(response.body).collect do |guess|
17
+ name = names.find { |n| n.to_s == guess["name"] }
18
+
19
+ if name.is_a?(String)
20
+ name = Name.new(guess["name"])
21
+ end
22
+
23
+ name.tap do |n|
24
+ n.gender = guess["gender"].to_sym
25
+ n.probability = guess["probability"]
26
+ n.sample_size = guess["count"]
27
+ end
28
+ end
29
+ self.names
30
+ end
31
+ end
32
+
33
+ def url
34
+ url = "http://api.genderize.io/?"
35
+ name_queries = names.collect.with_index do |name, index|
36
+ "name[#{index}]=#{name}"
37
+ end
38
+ url + name_queries.join("&")
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,67 @@
1
+ module Gendered
2
+ class Name
3
+ VALID_GENDERS = %i(male female)
4
+
5
+ attr_reader :value
6
+
7
+ def initialize(value)
8
+ @value = value
9
+
10
+ @gender, @probability, @sample_size = nil, nil, nil
11
+ end
12
+
13
+ alias_method :to_s, :value
14
+
15
+ def guessed?
16
+ !!@gender
17
+ end
18
+
19
+ def guess!
20
+ Guesser.new(self).guess!
21
+ gender
22
+ end
23
+
24
+ def probability=(value)
25
+ decimal = BigDecimal(value.to_s)
26
+ raise ArgumentError, "value not between 0.01 and 1.0" if decimal <= 0 || decimal > 1
27
+
28
+ @probability = decimal
29
+ end
30
+
31
+ def probability
32
+ @probability || :unknown
33
+ end
34
+
35
+ def sample_size=(value)
36
+ integer = Integer(value)
37
+ raise ArgumentError, "value not greater than or equal to 0" if integer < 0
38
+
39
+ @sample_size = integer
40
+ end
41
+
42
+ def sample_size
43
+ @sample_size || :unknown
44
+ end
45
+
46
+ def gender=(value)
47
+ symbol = value.to_sym
48
+ raise ArgumentError, "not a valid gender" unless VALID_GENDERS.include?(symbol)
49
+ @gender = symbol
50
+ end
51
+
52
+ def gender
53
+ @gender || :not_guessed
54
+ end
55
+
56
+ def male?
57
+ return :not_guessed unless guessed?
58
+ gender == :male
59
+ end
60
+
61
+ def female?
62
+ return :not_guessed unless guessed?
63
+ gender == :female
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,34 @@
1
+ module Gendered
2
+ class NameList
3
+ include Enumerable
4
+
5
+ attr_reader :names
6
+
7
+ def initialize(values)
8
+ @names = Array(values).collect do |value|
9
+ case value
10
+ when String then Name.new(value)
11
+ when Name then value
12
+ end
13
+ end
14
+ end
15
+
16
+ def guess!
17
+ Guesser.new(names).guess!
18
+ names.collect(&:gender)
19
+ end
20
+
21
+ def each(&block)
22
+ names.each do |name|
23
+ block.call name
24
+ end
25
+ end
26
+
27
+ def [](value)
28
+ names.find do |name|
29
+ name.value == value
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Gendered
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ module Gendered
2
+ describe Guesser do
3
+
4
+ let :names do
5
+ ["Sean","Theresa"]
6
+ end
7
+
8
+ subject do
9
+ described_class.new names
10
+ end
11
+
12
+ it "is initialized with names" do
13
+ expect(subject.names).to eq names
14
+ end
15
+
16
+ it "creates the correct url" do
17
+ expect(subject.url).to eq "http://api.genderize.io/?name[0]=Sean&name[1]=Theresa"
18
+ end
19
+
20
+ it "cannot be initialized with an empty array" do
21
+ expect{described_class.new([])}.to raise_error ArgumentError
22
+ end
23
+
24
+ describe "#guess!" do
25
+ it "returns a valid guesses hash" do
26
+ names = subject.guess!
27
+ names.each do |name|
28
+ expect(name).to be_a Name
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Gendered
2
+ describe NameList do
3
+ subject do
4
+ described_class.new values
5
+ end
6
+ let :values do
7
+ ["Sean","Theresa"]
8
+ end
9
+ describe "#guess!" do
10
+ it "guesses correctly" do
11
+ guesser = double(Guesser)
12
+ expect(guesser).to receive(:guess!)
13
+ expect(Guesser).to receive(:new).with(subject.names).and_return(guesser)
14
+ subject.guess!
15
+ end
16
+ end
17
+ context "when the values are strings" do
18
+ it "sets the names" do
19
+ subject.names.each.with_index do |name, index|
20
+ expect(name.value).to eq values[index]
21
+ end
22
+ end
23
+ end
24
+ context "when the values are names" do
25
+ let :values do
26
+ [Name.new("Sean"),Name.new("Theresa")]
27
+ end
28
+ it "sets the names" do
29
+ expect(subject.names).to eq values
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,147 @@
1
+ module Gendered
2
+ describe Name do
3
+
4
+ let :value do
5
+ "Sean"
6
+ end
7
+
8
+ subject do
9
+ described_class.new value
10
+ end
11
+
12
+ it "initializes with a value" do
13
+ expect(subject.value).to eq value
14
+ end
15
+
16
+ describe "#to_s" do
17
+ it "converts with its value" do
18
+ expect(subject.to_s).to eq subject.value
19
+ end
20
+ end
21
+
22
+ describe "guess!" do
23
+ it "returns the gender" do
24
+ expect(subject.guess!).to eq :male
25
+ end
26
+ end
27
+
28
+ describe "#gender=" do
29
+ described_class::VALID_GENDERS.each do |value|
30
+ it "can set the gender to #{value}" do
31
+ subject.gender = value
32
+ expect(subject.gender).to eq value
33
+ end
34
+ end
35
+ it "raises an argument error if the gender is set to something invalid" do
36
+ %w(eunich).each do |value|
37
+ expect{subject.gender = value}.to raise_error(ArgumentError)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#gender" do
43
+ it "is not_guessed" do
44
+ expect(subject.gender).to eq :not_guessed
45
+ end
46
+ end
47
+
48
+ context "when the gender is male" do
49
+ before { subject.gender = :male }
50
+ it "is male" do
51
+ expect(subject).to be_male
52
+ end
53
+ it "is not female" do
54
+ expect(subject).to_not be_female
55
+ end
56
+ end
57
+
58
+ context "when the gender is female" do
59
+ before { subject.gender = :female }
60
+ it "is female" do
61
+ expect(subject).to be_female
62
+ end
63
+ it "is not male" do
64
+ expect(subject).to_not be_male
65
+ end
66
+ end
67
+
68
+ context "when the gender is not set" do
69
+ describe "#male?" do
70
+ it "is not_guessed" do
71
+ expect(subject.male?).to eq :not_guessed
72
+ end
73
+ end
74
+ describe "#female?" do
75
+ it "is not_guessed" do
76
+ expect(subject.female?).to eq :not_guessed
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#guessed" do
82
+ context "when the gender is set" do
83
+ before do
84
+ subject.gender = :male
85
+ end
86
+ it "is guessed" do
87
+ expect(subject).to be_guessed
88
+ end
89
+ end
90
+ context "when the gender is not set" do
91
+ it "is not guessed" do
92
+ expect(subject).to_not be_guessed
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#probability=" do
98
+ it "can set probability greater than 0 and less than or equal to 1" do
99
+ probabilities = [BigDecimal("0.01")]
100
+ until probabilities.last == 1
101
+ probabilities << (probabilities.last + BigDecimal("0.01"))
102
+ end
103
+ probabilities.each do |p|
104
+ subject.probability = p
105
+ expect(subject.probability).to eq BigDecimal(p.to_s)
106
+ end
107
+ end
108
+ it "raises an ArgumentError if the value is 0" do
109
+ expect{subject.probability = 0}.to raise_error(ArgumentError)
110
+ end
111
+ it "raises an ArgumentError if the value is greater than 1" do
112
+ expect{subject.probability = 1.01}.to raise_error(ArgumentError)
113
+ end
114
+ it "raises an ArgumentError if the value can't convert to a decimal" do
115
+ expect{subject.probability = "not a decimal"}.to raise_error(ArgumentError)
116
+ end
117
+ end
118
+
119
+ describe "#sample_size=" do
120
+ it "raises an ArgumentError if the value can't be converted to an Integer" do
121
+ expect{subject.sample_size = "not an integer"}.to raise_error(ArgumentError)
122
+ end
123
+ it "can set an integer sample size greater than or equal to 0" do
124
+ (0..1).each do |value|
125
+ subject.sample_size = value
126
+ expect(subject.sample_size).to eq value
127
+ end
128
+ end
129
+ it "raises an ArgumentError if the value is less than 0" do
130
+ expect{subject.sample_size = -1}.to raise_error(ArgumentError)
131
+ end
132
+ end
133
+
134
+ describe "#probability" do
135
+ it "is :unknown unless set" do
136
+ expect(subject.probability).to eq :unknown
137
+ end
138
+ end
139
+
140
+ describe "#sample_size" do
141
+ it "is :unknown unless set" do
142
+ expect(subject.sample_size).to eq :unknown
143
+ end
144
+ end
145
+
146
+ end
147
+ end
@@ -0,0 +1,5 @@
1
+ require "gendered"
2
+
3
+ RSpec.configure do |config|
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gendered
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Devine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Guess the gender of a name.
70
+ email:
71
+ - barelyknown@icloud.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".bundle/config"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - exec/bundler
84
+ - exec/htmldiff
85
+ - exec/ldiff
86
+ - exec/rake
87
+ - exec/rspec
88
+ - gendered.gemspec
89
+ - lib/gendered.rb
90
+ - lib/gendered/guesser.rb
91
+ - lib/gendered/name.rb
92
+ - lib/gendered/name_list.rb
93
+ - lib/gendered/version.rb
94
+ - spec/lib/gendered/guesser_spec.rb
95
+ - spec/lib/gendered/name_list_spec.rb
96
+ - spec/lib/gendered/name_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: ''
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Guess the gender of a name.
122
+ test_files:
123
+ - spec/lib/gendered/guesser_spec.rb
124
+ - spec/lib/gendered/name_list_spec.rb
125
+ - spec/lib/gendered/name_spec.rb
126
+ - spec/spec_helper.rb
127
+ has_rdoc: