deordinalize 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -7
- data/lib/deordinalize.rb +4 -0
- data/lib/deordinalize/version.rb +1 -1
- data/spec/deordinalize/deordinalize_spec.rb +19 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -15,18 +15,24 @@ Usage:
|
|
15
15
|
|
16
16
|
We can deordinalize numeric ordinals:
|
17
17
|
|
18
|
-
'1st'
|
19
|
-
'11th'
|
20
|
-
'99th'
|
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
|
25
|
-
'eleventh'.deordinalize
|
26
|
-
'ninety-ninth'.deordinalize
|
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
|
37
|
+
page.find( :xpath, "//li[#{ordinal.deordinalize!}]" ).click
|
32
38
|
end
|
data/lib/deordinalize.rb
CHANGED
data/lib/deordinalize/version.rb
CHANGED
@@ -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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2011-07-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|