genderify 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,6 +10,14 @@ Genderify Strings using this simple syntax:
10
10
  => "He recommended his own book"
11
11
  ```
12
12
 
13
+ You can also pass an object that responds to `gender` call, returning gender
14
+ symbol ie :f (see full list in lib/genderify/string_ext.rb)
15
+
16
+ ```ruby
17
+ >> "(He|She) favorited your post!".genderify(user)
18
+ => "She favorited your post!".
19
+ ```
20
+
13
21
  ## Installation
14
22
 
15
23
  Add this line to your application's Gemfile:
@@ -4,23 +4,28 @@ String.class_eval do
4
4
 
5
5
  # Genderifies string. This is done by replacing every occurence of (x|y)
6
6
  # with either left (x) or right part (y) of it based on the gender provided as argument.
7
- # If argument of function is :f, 'f', :F, 'F', 1 or '1' it will pick the right side. \
8
- # Anything else, including omitting it will us the left side as replacement.
7
+ # If argument of function is :f, 'f', :F, 'F', 1, '1', :female or 'female' it will pick
8
+ # the right side. Anything else, including nil, will use the left side as replacement.
9
9
  # Hm, is this sexist?
10
10
  #
11
+ # Argument can also be an object that responds to 'gender' call. Returning value of such
12
+ # function will be applied to stated rules above.
13
+ #
11
14
  # Example:
15
+ #
12
16
  # >> "About (him|her)".genderify(:f)
13
17
  # => "About her"
14
- def genderify(gender=nil)
18
+ #
19
+ def genderify(genderable)
20
+ gender = genderable.respond_to?(:gender) ? genderable.gender : genderable
15
21
  gsub(/\((.+?)\|(.+?)\)/) do
16
22
  case gender
17
- when :f, 'f', :F, 'F', 1, '1'
23
+ when :f, 'f', :F, 'F', 1, '1', :female, 'female'
18
24
  $2
19
25
  else
20
26
  $1
21
27
  end
22
28
  end
23
-
24
29
  end
25
30
 
26
31
  end
@@ -1,3 +1,3 @@
1
1
  module Genderify
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,17 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require "ostruct"
3
4
  require "test/unit"
4
5
  require "genderify"
5
6
 
6
7
  class StringExtTest < Test::Unit::TestCase
7
8
 
8
9
  def test_0_variants
9
- assert_equal "vozi", "vozi".genderify
10
- assert_equal "vozi", "vozi".genderify(:f)
10
+ assert_equal "foo", "foo".genderify(:f)
11
11
  end
12
12
 
13
13
  def test_1_variant
14
- assert_equal "napisao", "napisa(o|la)".genderify
14
+ assert_equal "About him", "About (him|her)".genderify(:m)
15
15
  end
16
16
 
17
17
  def test_2_variants
@@ -19,4 +19,9 @@ class StringExtTest < Test::Unit::TestCase
19
19
  assert_equal "Gde si krenuo, sad će da postavljaju... Jesi li siguran?", str.genderify(:m)
20
20
  assert_equal "Gde si krenula, sad će da postavljaju... Jesi li sigurna?", str.genderify(:f)
21
21
  end
22
+
23
+ def test_genderable_object
24
+ user = OpenStruct.new(gender: 'female', name: 'Jane')
25
+ assert_equal "She is an addict", "(He|She) is an addict".genderify(user)
26
+ end
22
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genderify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: