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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f900977dce6ce532aaaaeb0eac75f034ef6f9a6f
4
- data.tar.gz: 4a9dfe4d19dd6a31893c72d49d3f692eaea1b5aa
3
+ metadata.gz: 9d5896e1856dac2e401a587209c71b2cae369821
4
+ data.tar.gz: 6a116943a73774552baf065423aba613f3b4642c
5
5
  SHA512:
6
- metadata.gz: 8ad68c57f62525bfc471f944f8242692debe6473a82bfb15c2379cc02d9f9704d7206e126682d4c59d3c2e07fdd3da13474789f779baa76980c02455d82131f7
7
- data.tar.gz: 7d9c2260901360ef81bd9282d0373a1bea5df76a721e1973d79216f83276fda5fb9e0a9a74202d48277479d3ab328670a3d4380e7874ba9fddb4b327893b022b
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: ""
@@ -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? ? nil : abbr.to_s.first.downcase
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
- case
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
@@ -1,3 +1,3 @@
1
1
  module Genderize
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
Binary file
@@ -56,3 +56,23 @@ Migrating to CreateUsers (20130506080641)
56
56
  SQL (0.3ms) 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
   (2.5ms) commit transaction
58
58
  User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
59
+  (0.1ms) begin transaction
60
+ SQL (0.4ms) 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
+  (0.5ms) commit transaction
62
+ User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
63
+  (0.0ms) begin transaction
64
+ SQL (0.3ms) 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
+  (2.4ms) commit transaction
66
+ User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
67
+  (0.0ms) begin transaction
68
+ SQL (0.4ms) 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
+  (2.3ms) commit transaction
70
+ User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
71
+  (0.0ms) begin transaction
72
+ SQL (0.4ms) 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
+  (2.4ms) commit transaction
74
+ User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
75
+  (0.1ms) begin transaction
76
+ SQL (0.4ms) 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
+  (2.4ms) commit transaction
78
+ User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
@@ -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 nil" do
40
- expect(blank.name).to be_nil
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 nil" do
69
- expect(blank.abbr).to be_nil
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 nil" do
98
- expect(blank.subject).to be_nil
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 nil" do
126
- expect(blank.object).to be_nil
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 nil" do
155
- expect(blank.possessive).to be_nil
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 nil" do
185
- expect(blank.casual).to be_nil
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 eql(male.abbr)
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 be_an_instance_of(String)
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 eql(male.abbr.capitalize)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genderize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bodacious