deordinalize 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -15,18 +15,24 @@ Usage:
15
15
 
16
16
  We can deordinalize numeric ordinals:
17
17
 
18
- '1st' # => 1
19
- '11th' # => 11
20
- '99th' # => 99
18
+ '1st'.deordinalize # => 1
19
+ '11th'.deordinalize # => 11
20
+ '99th'.deordinalize # => 99
21
21
 
22
22
  Or we can deordinalize more verbose ordinals:
23
23
 
24
- 'first'.deordinalize # => 1
25
- 'eleventh'.deordinalize # => 11
26
- 'ninety-ninth'.deordinalize # => 99
24
+ 'first'.deordinalize # => 1
25
+ 'eleventh'.deordinalize # => 11
26
+ 'ninety-ninth'.deordinalize # => 99
27
+
28
+ Add a bang to the method to get the zero-based index of your ordinal:
29
+
30
+ 'first'.deordinalize! # => 0
31
+ 'eleventh'.deordinalize! # => 10
32
+ 'ninety-ninth'.deordinalize! # => 98
27
33
 
28
34
  This is meant to be hella useful in cucumber steps, like:
29
35
 
30
36
  When /^I click on the (.+) item in the list$/ do |ordinal|
31
- page.find( :xpath, "//li[ordinal.deordinalize - 1]" ).click
37
+ page.find( :xpath, "//li[#{ordinal.deordinalize!}]" ).click
32
38
  end
@@ -75,6 +75,10 @@ module Deordinalize
75
75
 
76
76
  end
77
77
 
78
+ def deordinalize!
79
+ self.deordinalize - 1
80
+ end
81
+
78
82
  end
79
83
 
80
84
  String.send :include, Deordinalize
@@ -1,3 +1,3 @@
1
1
  module Deordinalize
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,6 +4,9 @@ describe "a string" do
4
4
  it "should respond to deordinalize" do
5
5
  "hello".should respond_to(:deordinalize)
6
6
  end
7
+ it "should respond to deordinalize!" do
8
+ "hello".should respond_to(:deordinalize!)
9
+ end
7
10
 
8
11
  context "when not an ordinal" do
9
12
  it "should return nil" do
@@ -15,6 +18,8 @@ describe "a string" do
15
18
 
16
19
  cases = (1..100).to_a
17
20
 
21
+ # using deordinalize straight up should give the ordinal index
22
+
18
23
  cases.map { |i| [ i.en.ordinal, i ] }.each do |ordinal, number|
19
24
  it "should deordinalize '#{ordinal}' to #{number}" do
20
25
  ordinal.deordinalize.should == number
@@ -27,4 +32,18 @@ describe "a string" do
27
32
  end
28
33
  end
29
34
 
35
+ # adding a bang should give the zero-based index
36
+
37
+ cases.map { |i| [ i.en.ordinal, i ] }.each do |ordinal, number|
38
+ it "should deordinalize '#{ordinal}' to #{number - 1}" do
39
+ ordinal.deordinalize!.should == ( number - 1 )
40
+ end
41
+ end
42
+
43
+ cases.map { |i| [ i.en.numwords.en.ordinal, i ] }.each do |ordinal, number|
44
+ it "should deordinalize '#{ordinal}' to #{number - 1}" do
45
+ ordinal.deordinalize!.should == ( number - 1 )
46
+ end
47
+ end
48
+
30
49
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deordinalize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Ruppel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-22 00:00:00 -07:00
18
+ date: 2011-07-03 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency