number_postfixr 1.0.0 → 1.1.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/README.rdoc CHANGED
@@ -1,6 +1,24 @@
1
1
  = number_postfixr
2
2
 
3
- Description goes here.
3
+ 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.
4
+
5
+ To install (gemcutter.org):
6
+ gem install number_postfixr
7
+ To use:
8
+ require 'number_postfixr'
9
+
10
+ PostFixr.postfix(1)
11
+ #=> "1st"
12
+
13
+ PostFixr.postfix(18)
14
+ #=> "18th"
15
+
16
+ PostFixr.postfix(103)
17
+ #=> "103rd"
18
+
19
+ array = [1, 8, 19, 21, 108]
20
+ PostFixr.postfix_array(array)
21
+ #=> ["1st", "8th", "19th", "21st", "108th"]
4
22
 
5
23
  == Note on Patches/Pull Requests
6
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,23 +1,11 @@
1
1
  class PostFixr
2
- @@postfix = ["st", "nd", "rd", "th"]
3
-
4
2
  def self.postfix(number)
5
- fix = number.to_s
6
- if fix.length < 2 or (fix.length == 2 and fix[0] != "1") or (fix.length > 2)
7
- if fix[-1] == "1"
8
- fix += @@postfix[0]
9
- elsif fix[-1] == "2"
10
- fix += @@postfix[1]
11
- elsif fix[-1] == "3"
12
- fix += @@postfix[2]
13
- else
14
- fix += @@postfix[3]
15
- end
3
+ fix = number.to_i.abs
4
+ if (10...20).include?(fix) then
5
+ fix.to_s << 'th'
16
6
  else
17
- fix += @@postfix[3]
7
+ fix.to_s << %w{th st nd rd th th th th th th}[fix % 10]
18
8
  end
19
-
20
- return fix
21
9
  end
22
10
 
23
11
  def self.postfix_array(array)
@@ -28,4 +16,10 @@ class PostFixr
28
16
 
29
17
  return fix
30
18
  end
31
- end
19
+ end
20
+
21
+ class Numeric
22
+ def postfix
23
+ PostFixr.postfix(self)
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{number_postfixr}
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Luke van der Hoeven"]
12
+ s.date = %q{2010-01-26}
13
+ s.description = %q{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.}
14
+ s.email = %q{hungerandthirst@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/number_postfixr.rb",
27
+ "number_postfixr.gemspec",
28
+ "test.rb",
29
+ "test/helper.rb",
30
+ "test/test_number_postfixr.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/plukevdh/number_postfixr}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Simple library to turn fixnums into strings with sequence postfixes attached (i.e. 1st, 2nd -or- first, second}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_number_postfixr.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<shoulda>, [">= 2.10"])
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 2.10"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 2.10"])
53
+ end
54
+ end
55
+
data/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'lib/number_postfixr'
2
+
3
+ puts PostFixr.postfix(21)
@@ -38,4 +38,11 @@ class TestNumberPostfixr < Test::Unit::TestCase
38
38
  assert_equal "96th", fixed[4]
39
39
  assert_equal "30th", fixed[5]
40
40
  end
41
+
42
+ should "return correctly postfixed numbers from Numeric" do
43
+ assert_equal "1st", 1.postfix
44
+ assert_equal "22nd", 22.postfix
45
+ assert_equal "63rd", 63.postfix
46
+ assert_equal "19th", 19.postfix
47
+ end
41
48
  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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke van der Hoeven
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-25 00:00:00 -05:00
12
+ date: 2010-01-26 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,8 @@ files:
39
39
  - Rakefile
40
40
  - VERSION
41
41
  - lib/number_postfixr.rb
42
+ - number_postfixr.gemspec
43
+ - test.rb
42
44
  - test/helper.rb
43
45
  - test/test_number_postfixr.rb
44
46
  has_rdoc: true