number_postfixr 0.0.1 → 1.0.0
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/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/number_postfixr.rb +5 -5
- data/test/test_number_postfixr.rb +37 -3
- metadata +12 -3
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ begin
|
|
10
10
|
gem.email = "hungerandthirst@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/plukevdh/number_postfixr"
|
12
12
|
gem.authors = ["Luke van der Hoeven"]
|
13
|
+
gem.add_dependency("shoulda", ">= 2.10")
|
13
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
15
|
end
|
15
16
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/lib/number_postfixr.rb
CHANGED
@@ -3,12 +3,12 @@ class PostFixr
|
|
3
3
|
|
4
4
|
def self.postfix(number)
|
5
5
|
fix = number.to_s
|
6
|
-
if fix.length < 2 or (fix.length
|
7
|
-
if
|
6
|
+
if fix.length < 2 or (fix.length == 2 and fix[0] != "1") or (fix.length > 2)
|
7
|
+
if fix[-1] == "1"
|
8
8
|
fix += @@postfix[0]
|
9
|
-
elsif
|
9
|
+
elsif fix[-1] == "2"
|
10
10
|
fix += @@postfix[1]
|
11
|
-
elsif
|
11
|
+
elsif fix[-1] == "3"
|
12
12
|
fix += @@postfix[2]
|
13
13
|
else
|
14
14
|
fix += @@postfix[3]
|
@@ -20,7 +20,7 @@ class PostFixr
|
|
20
20
|
return fix
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.
|
23
|
+
def self.postfix_array(array)
|
24
24
|
fix = []
|
25
25
|
array.each do |elem|
|
26
26
|
fix << postfix(elem)
|
@@ -1,7 +1,41 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestNumberPostfixr < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
should "return '1st'" do
|
5
|
+
assert_equal "1st", PostFixr.postfix(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
should "return array of postfixed numbers" do
|
9
|
+
ary = [1,2,3,4,5]
|
10
|
+
fixed = PostFixr.postfix_array(ary)
|
11
|
+
|
12
|
+
assert_equal "1st", fixed[0]
|
13
|
+
assert_equal "2nd", fixed[1]
|
14
|
+
assert_equal "3rd", fixed[2]
|
15
|
+
assert_equal "4th", fixed[3]
|
16
|
+
assert_equal "5th", fixed[4]
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return teens correctly postfixed" do
|
20
|
+
ary = [11,12,13,14,15]
|
21
|
+
fixed = PostFixr.postfix_array(ary)
|
22
|
+
|
23
|
+
assert_equal "11th", fixed[0]
|
24
|
+
assert_equal "12th", fixed[1]
|
25
|
+
assert_equal "13th", fixed[2]
|
26
|
+
assert_equal "14th", fixed[3]
|
27
|
+
assert_equal "15th", fixed[4]
|
28
|
+
end
|
29
|
+
|
30
|
+
should "return randomly selected postfixed numbers" do
|
31
|
+
ary = [21, 1003, 79, 2, 96, 30]
|
32
|
+
fixed = PostFixr.postfix_array(ary)
|
33
|
+
|
34
|
+
assert_equal "21st", fixed[0]
|
35
|
+
assert_equal "1003rd", fixed[1]
|
36
|
+
assert_equal "79th", fixed[2]
|
37
|
+
assert_equal "2nd", fixed[3]
|
38
|
+
assert_equal "96th", fixed[4]
|
39
|
+
assert_equal "30th", fixed[5]
|
40
|
+
end
|
7
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: number_postfixr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke van der Hoeven
|
@@ -11,8 +11,17 @@ cert_chain: []
|
|
11
11
|
|
12
12
|
date: 2010-01-25 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.10"
|
24
|
+
version:
|
16
25
|
description: I found the need to be able to have counting sequences from simple fixnums, and I didn't know what to search for to see if such functionality existed, so I just created it... Hope this helps somebody beyond just me.
|
17
26
|
email: hungerandthirst@gmail.com
|
18
27
|
executables: []
|