possessify 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,10 @@
1
1
  = Possessify
2
2
 
3
- Possessify extends the Ruby String class adding functionality to make strings possessive and non-possessive. It also provides a possessive? checker method.
3
+ Possessify extends the Ruby String class adding functionality to make strings possessive and non-possessive. It also provides possessive? and non_possessive? checker methods.
4
+
5
+ == Installation
6
+
7
+ gem install possessify
4
8
 
5
9
  == Examples
6
10
 
@@ -12,6 +16,9 @@ Possessify extends the Ruby String class adding functionality to make strings po
12
16
 
13
17
  "Dave's".possessive? #=> true
14
18
  "Dave".possessive? #=> false
19
+
20
+ "Dave's".non_possessive? #=> false
21
+ "Dave".non_possessive? #=> true
15
22
 
16
23
 
17
24
  Copyright (c) 2011 David Busse, released under the MIT license
data/Rakefile CHANGED
@@ -21,6 +21,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
21
21
  rdoc.rdoc_dir = 'rdoc'
22
22
  rdoc.title = 'Possessify'
23
23
  rdoc.options << '--line-numbers' << '--inline-source'
24
- rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('README.rdoc')
25
25
  rdoc.rdoc_files.include('lib/**/*.rb')
26
26
  end
@@ -1,14 +1,28 @@
1
1
  module Possessify
2
2
 
3
3
  String.class_eval do
4
+
5
+ ##
6
+ # :call-seq:
7
+ # str.possessive => new_str
8
+ #
9
+ # Returns a new string that is the possessive form of <i>str</i>.
10
+ # "Dave".possessive #=> "Dave's"
11
+ # "Xerxes".possessive #=> "Xerxes'"
4
12
  def possessive
5
- str = self
6
- unless str.possessive? || str.blank?
7
- str = str + (str[-1,1] && str[-1,1].downcase == "s" ? "'" : "'s")
13
+ unless self.possessive? || self.blank?
14
+ str = self + (self[-1,1] && self[-1,1].downcase == "s" ? "'" : "'s")
8
15
  end
9
- str
16
+ str || self
10
17
  end
11
-
18
+
19
+ ##
20
+ # :call-seq:
21
+ # str.non_possessive => new_str
22
+ #
23
+ # Returns a new string that is the non-possessive form of <i>str</i>.
24
+ # "Dave's".non_possessive #=> "Dave"
25
+ # "Xerxes'".non_possessive #=> "Xerxes"
12
26
  def non_possessive
13
27
  if self.possessive?
14
28
  unless self.chomp!("'s")
@@ -18,9 +32,28 @@ module Possessify
18
32
  self
19
33
  end
20
34
 
35
+ ##
36
+ # :call-seq:
37
+ # str.possessive? => true or false
38
+ #
39
+ # Returns <code>true</code> if <i>str</i> is possessive.
40
+ # "Dave's".possessive? #=> true
41
+ # "Dave".possessive? #=> false
21
42
  def possessive?
22
43
  self[-2,2] && (self[-2,2].downcase == "'s" || self[-2,2].downcase == "s'")
23
44
  end
45
+
46
+ ##
47
+ # :call-seq:
48
+ # str.non_possessive? => true or false
49
+ #
50
+ # Returns <code>true</code> if <i>str</i> is not in possessive form.
51
+ # "Dave's".non_possessive? #=> false
52
+ # "Dave".non_possessive? #=> true
53
+ def non_possessive?
54
+ !self.possessive?
55
+ end
56
+
24
57
  end
25
58
 
26
59
  end
@@ -1,3 +1,3 @@
1
1
  module Possessify
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,36 +1,50 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class PossessifyTest < ActiveSupport::TestCase
4
- test "string not ending in s possessive" do
4
+
5
+ # tests for possessive method
6
+ test "should make singular string possessive" do
5
7
  assert_equal "Dave's", "Dave".possessive
6
8
  end
7
9
 
8
- test "string ending in s possessive" do
9
- assert_equal "James'", "James".possessive
10
- assert_equal "JameS'", "JameS".possessive
11
- end
12
-
13
- test "string already possessive" do
14
- assert_equal "Dave's", "Dave's".possessive
15
- assert_equal "James'", "James'".possessive
10
+ test "should make string ending in s possessive" do
11
+ assert_equal "Xerxes'", "Xerxes".possessive
12
+ assert_equal "XerxeS'", "XerxeS".possessive
16
13
  end
17
14
 
18
- test "short string" do
15
+ test "should make single character string possesive" do
19
16
  assert_equal "D's", "D".possessive
20
17
  assert_equal "S'", "S".possessive
21
18
  end
22
19
 
23
- test "blanks string" do
20
+ test "should do nothing if string already possessive" do
21
+ assert_equal "Dave's", "Dave's".possessive
22
+ assert_equal "Xerxes'", "Xerxes'".possessive
23
+ end
24
+
25
+ test "should do nothing if string is empty" do
24
26
  assert_equal "", "".possessive
25
27
  end
26
28
 
27
- test "possesive string non_possesive" do
29
+ # tests for non_possessive method
30
+ test "should make singular possessive string non-possesive" do
28
31
  assert_equal "Dave", "Dave's".non_possessive
29
32
  end
30
33
 
31
- test "plural possesive string non_possesive" do
32
- assert_equal "James", "James'".non_possessive
33
- assert_equal "JameS", "JameS'".non_possessive
34
+ test "should make possesive string ending in s non_possesive" do
35
+ assert_equal "Xerxes", "Xerxes'".non_possessive
36
+ assert_equal "XerxeS", "XerxeS'".non_possessive
37
+ end
38
+
39
+ # tests for possessive? method
40
+ test "should return true for possessive string" do
41
+ assert_equal true, "Dave's".possessive?
42
+ assert_equal true, "Xerxes'".possessive?
43
+ end
44
+
45
+ test "should return false for non-possessive string" do
46
+ assert_equal false, "Dave".possessive?
47
+ assert_equal false, "Xerxes".possessive?
34
48
  end
35
49
 
36
50
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: possessify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Busse
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 -06:00
18
+ date: 2011-02-01 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies: []
21
21