genderize 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/locales/genderize.en.yml +10 -5
- data/config/locales/genderize.es.yml +9 -4
- data/lib/genderize/gender.rb +29 -24
- data/lib/genderize/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +20 -0
- data/spec/lib/gender_spec.rb +20 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d5896e1856dac2e401a587209c71b2cae369821
|
4
|
+
data.tar.gz: 6a116943a73774552baf065423aba613f3b4642c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f1afe0ebcb4288691692cebffc584697e5c83cd328ee9165892b98571d8bcddeed28270dd5ae492ccc6b87cb851bff25b4a8257328926fd5c1030dd024cf748
|
7
|
+
data.tar.gz: 5140e5c42950d1f64e6cc5715a31d37eea13fa7f65a6ff39c4abdd15e8d47a345927e89e7cc4afe50218280435baba9240312af4bf7ac90ed9248ef422fcabb3
|
@@ -3,21 +3,26 @@ en:
|
|
3
3
|
name:
|
4
4
|
masculine: "male"
|
5
5
|
feminine: "female"
|
6
|
-
|
6
|
+
blank: ""
|
7
|
+
|
7
8
|
# pronouns
|
8
9
|
subject:
|
9
10
|
masculine: 'he'
|
10
11
|
feminine: 'she'
|
11
|
-
|
12
|
+
blank: "they"
|
13
|
+
|
12
14
|
object:
|
13
15
|
masculine: 'him'
|
14
16
|
feminine: 'her'
|
15
|
-
|
17
|
+
blank: "them"
|
18
|
+
|
16
19
|
possessive:
|
17
20
|
masculine: 'his'
|
18
21
|
feminine: 'her'
|
19
|
-
|
22
|
+
blank: "their"
|
23
|
+
|
20
24
|
# Other forms
|
21
25
|
casual:
|
22
26
|
masculine: guy
|
23
|
-
feminine: girl
|
27
|
+
feminine: girl
|
28
|
+
blank: person
|
@@ -3,21 +3,26 @@ es:
|
|
3
3
|
name:
|
4
4
|
masculine: "hombre"
|
5
5
|
feminine: "mujer"
|
6
|
-
|
6
|
+
blank: ""
|
7
|
+
|
7
8
|
# pronouns
|
8
9
|
subject:
|
9
10
|
masculine: 'él'
|
10
11
|
feminine: 'ella'
|
11
|
-
|
12
|
+
blank: ""
|
13
|
+
|
12
14
|
object:
|
13
15
|
masculine: 'él'
|
14
16
|
feminine: 'ella'
|
15
|
-
|
17
|
+
blank: ""
|
18
|
+
|
16
19
|
possessive:
|
17
20
|
masculine: 'suyo'
|
18
21
|
feminine: 'suya'
|
19
|
-
|
22
|
+
blank: ""
|
23
|
+
|
20
24
|
# Other forms
|
21
25
|
casual:
|
22
26
|
masculine: chico
|
23
27
|
feminine: chica
|
28
|
+
blank: ""
|
data/lib/genderize/gender.rb
CHANGED
@@ -1,67 +1,72 @@
|
|
1
1
|
module Genderize
|
2
2
|
class Gender
|
3
|
-
|
3
|
+
|
4
4
|
include I18n
|
5
|
-
|
5
|
+
|
6
|
+
# Maps the gender abbreviation name to the full name for translation keys
|
7
|
+
ABR_KEY_NAME_MAPPING = { "" => "blank", "m" => "masculine", "f" => "feminine" }
|
8
|
+
|
9
|
+
|
6
10
|
attr_reader :abbr
|
7
|
-
|
11
|
+
|
8
12
|
def initialize(abbr)
|
9
13
|
unless abbr.blank? or abbr.to_s =~ /\A(f|m|female|male)\Z/i
|
10
|
-
raise "Invalid abbreviation: '#{abbr}'"
|
14
|
+
raise "Invalid abbreviation: '#{abbr}'"
|
11
15
|
end
|
12
|
-
@abbr = abbr.blank? ?
|
16
|
+
@abbr = abbr.blank? ? '' : abbr.to_s.first.downcase
|
13
17
|
end
|
14
|
-
|
18
|
+
|
15
19
|
def name
|
16
20
|
@name ||= translation_for("name")
|
17
21
|
end
|
18
|
-
|
22
|
+
|
19
23
|
def subject
|
20
24
|
@subject ||= translation_for("subject")
|
21
25
|
end
|
22
|
-
|
26
|
+
|
23
27
|
def object
|
24
28
|
@object ||= translation_for("object")
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
def possessive
|
28
32
|
@possessive ||= translation_for("possessive")
|
29
33
|
end
|
30
|
-
|
34
|
+
|
31
35
|
def casual
|
32
36
|
@casual ||= translation_for("casual")
|
33
37
|
end
|
34
|
-
|
38
|
+
|
35
39
|
def capital_abbr
|
36
40
|
abbr.capitalize
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
def male?
|
40
44
|
abbr == 'm'
|
41
45
|
end
|
42
|
-
|
46
|
+
|
43
47
|
def female?
|
44
48
|
abbr == 'f'
|
45
49
|
end
|
46
|
-
|
50
|
+
|
51
|
+
def blank?
|
52
|
+
abbr == ""
|
53
|
+
end
|
54
|
+
|
47
55
|
def to_s
|
48
56
|
abbr
|
49
57
|
end
|
50
|
-
|
58
|
+
|
51
59
|
def ==(val)
|
52
60
|
abbr.to_s == val.to_s
|
53
61
|
end
|
54
|
-
|
62
|
+
|
63
|
+
|
55
64
|
private
|
56
|
-
|
65
|
+
|
66
|
+
|
57
67
|
def translation_for(key)
|
58
|
-
|
59
|
-
when male? then I18n.t("genderize.#{key}.masculine")
|
60
|
-
when female? then I18n.t("genderize.#{key}.feminine")
|
61
|
-
else
|
62
|
-
nil
|
63
|
-
end
|
68
|
+
I18n.t("genderize.#{key}.#{ABR_KEY_NAME_MAPPING[abbr]}")
|
64
69
|
end
|
65
|
-
|
70
|
+
|
66
71
|
end
|
67
72
|
end
|
data/lib/genderize/version.rb
CHANGED
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/dummy/log/test.log
CHANGED
@@ -56,3 +56,23 @@ Migrating to CreateUsers (20130506080641)
|
|
56
56
|
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:33:00.356946"], ["updated_at", "2016-05-27 13:33:00.356946"]]
|
57
57
|
[1m[36m (2.5ms)[0m [1mcommit transaction[0m
|
58
58
|
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
59
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
60
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:56:15.467527"], ["updated_at", "2016-05-27 13:56:15.467527"]]
|
61
|
+
[1m[36m (0.5ms)[0m [1mcommit transaction[0m
|
62
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
63
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
64
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:57:19.171265"], ["updated_at", "2016-05-27 13:57:19.171265"]]
|
65
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
66
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
67
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
68
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:57:59.175258"], ["updated_at", "2016-05-27 13:57:59.175258"]]
|
69
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
70
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
71
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
72
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:58:25.137246"], ["updated_at", "2016-05-27 13:58:25.137246"]]
|
73
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
74
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
75
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
76
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:58:39.130168"], ["updated_at", "2016-05-27 13:58:39.130168"]]
|
77
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
78
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
data/spec/lib/gender_spec.rb
CHANGED
@@ -11,6 +11,7 @@ describe Genderize::Gender do
|
|
11
11
|
it "should find the correct abbreviation" do
|
12
12
|
expect(Gender.new("female").abbr).to eql('f')
|
13
13
|
expect(Gender.new("male").abbr).to eql('m')
|
14
|
+
expect(Gender.new("").abbr).to eql('')
|
14
15
|
end
|
15
16
|
|
16
17
|
end
|
@@ -36,8 +37,8 @@ describe Genderize::Gender do
|
|
36
37
|
|
37
38
|
context "when blank" do
|
38
39
|
|
39
|
-
it "should be
|
40
|
-
expect(blank.name).to
|
40
|
+
it "should be ''" do
|
41
|
+
expect(blank.name).to eql("")
|
41
42
|
end
|
42
43
|
|
43
44
|
end
|
@@ -65,8 +66,8 @@ describe Genderize::Gender do
|
|
65
66
|
|
66
67
|
context "when blank" do
|
67
68
|
|
68
|
-
it "should be
|
69
|
-
expect(blank.abbr).to
|
69
|
+
it "should be ''" do
|
70
|
+
expect(blank.abbr).to eql("")
|
70
71
|
end
|
71
72
|
|
72
73
|
end
|
@@ -94,8 +95,8 @@ describe Genderize::Gender do
|
|
94
95
|
|
95
96
|
context "when blank" do
|
96
97
|
|
97
|
-
it "should be
|
98
|
-
expect(blank.subject).to
|
98
|
+
it "should be 'they'" do
|
99
|
+
expect(blank.subject).to eql("they")
|
99
100
|
end
|
100
101
|
|
101
102
|
end
|
@@ -122,8 +123,8 @@ describe Genderize::Gender do
|
|
122
123
|
|
123
124
|
context "when blank" do
|
124
125
|
|
125
|
-
it "should be
|
126
|
-
expect(blank.object).to
|
126
|
+
it "should be 'them'" do
|
127
|
+
expect(blank.object).to eql("them")
|
127
128
|
end
|
128
129
|
|
129
130
|
end
|
@@ -151,8 +152,8 @@ describe Genderize::Gender do
|
|
151
152
|
|
152
153
|
context "when blank" do
|
153
154
|
|
154
|
-
it "should be
|
155
|
-
expect(blank.possessive).to
|
155
|
+
it "should be 'their'" do
|
156
|
+
expect(blank.possessive).to eql("their")
|
156
157
|
end
|
157
158
|
|
158
159
|
end
|
@@ -181,8 +182,8 @@ describe Genderize::Gender do
|
|
181
182
|
|
182
183
|
context "when blank" do
|
183
184
|
|
184
|
-
it "should be
|
185
|
-
expect(blank.casual).to
|
185
|
+
it "should be 'person'" do
|
186
|
+
expect(blank.casual).to eql("person")
|
186
187
|
end
|
187
188
|
|
188
189
|
end
|
@@ -193,13 +194,15 @@ describe Genderize::Gender do
|
|
193
194
|
describe :to_s do
|
194
195
|
|
195
196
|
it "should equal the abbr value" do
|
196
|
-
expect(male.to_s).to
|
197
|
+
expect(male.to_s).to eql(male.abbr)
|
197
198
|
expect(female.to_s).to eql(female.abbr)
|
199
|
+
expect(blank.to_s).to eql(blank.abbr)
|
198
200
|
end
|
199
201
|
|
200
202
|
it "returns a string" do
|
201
|
-
expect(male.to_s).to
|
203
|
+
expect(male.to_s).to be_an_instance_of(String)
|
202
204
|
expect(female.to_s).to be_an_instance_of(String)
|
205
|
+
expect(blank.to_s).to be_an_instance_of(String)
|
203
206
|
end
|
204
207
|
|
205
208
|
end
|
@@ -207,8 +210,9 @@ describe Genderize::Gender do
|
|
207
210
|
describe :capital_abbr do
|
208
211
|
|
209
212
|
it "should equal the abbr value capitalized" do
|
210
|
-
expect(male.capital_abbr).to
|
213
|
+
expect(male.capital_abbr).to eql(male.abbr.capitalize)
|
211
214
|
expect(female.capital_abbr).to eql(female.abbr.capitalize)
|
215
|
+
expect(blank.capital_abbr).to eql(blank.abbr.capitalize)
|
212
216
|
end
|
213
217
|
|
214
218
|
end
|
@@ -219,6 +223,7 @@ describe Genderize::Gender do
|
|
219
223
|
expect(male == "m").to be_truthy
|
220
224
|
expect(female == "f").to be_truthy
|
221
225
|
expect(blank == nil).to be_truthy
|
226
|
+
expect(blank == '').to be_truthy
|
222
227
|
end
|
223
228
|
|
224
229
|
it "should return false if not passed abbr value" do
|