ordinal 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ordinal.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Lumley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Ordinal
2
+
3
+ Converts a number (e.g. 1) to an ordinal number (e.g. 1st)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ordinal'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ordinal
18
+
19
+ ## Usage
20
+
21
+ 0.to_ordinal # 0
22
+ 1.to_ordinal # 1st
23
+ 5.to_ordinal # 5th
24
+ 23.to_ordinal # 23rd
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ require "ordinal/version"
2
+
3
+ module Ordinal
4
+
5
+ def to_ordinal
6
+
7
+ number = self.to_i
8
+
9
+ case
10
+ when number == 0
11
+ 0.to_s
12
+ when (number % 100 >= 11 and
13
+ number % 100 <= 13)
14
+ number.to_s << 'th'
15
+ else
16
+ number.to_s << suffixes[number % 10]
17
+ end
18
+
19
+ end
20
+
21
+ def suffixes
22
+ ['th','st','nd','rd','th','th','th','th','th','th']
23
+ end
24
+
25
+ end
26
+
27
+ class Numeric
28
+
29
+ include Ordinal
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module Ordinal
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ordinal/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["David Lumley", "Andrew Gallagher"]
6
+ gem.email = ["djlumley@me.com", "kivlor@gmail.com"]
7
+ gem.description = %q{
8
+ Converts a number (e.g. 1) to an ordinal number (e.g. 1st)
9
+ }
10
+ gem.summary = %q{
11
+ Converts a number (e.g. 1) to an ordinal number (e.g. 1st)
12
+ }
13
+ gem.homepage = "http://github.com/davidlumley/ordinal"
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.name = "ordinal"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Ordinal::VERSION
21
+
22
+ gem.add_development_dependency 'rspec', '~> 2.10'
23
+
24
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('lib/ordinal')
2
+
3
+ describe Ordinal do
4
+
5
+ test_cases = [
6
+ [0, '0'],
7
+ [1, '1st'],
8
+ [2, '2nd'],
9
+ [3, '3rd'],
10
+ [4, '4th'],
11
+ [5, '5th'],
12
+ [6, '6th'],
13
+ [7, '7th'],
14
+ [8, '8th'],
15
+ [9, '9th'],
16
+ [10, '10th'],
17
+ [11, '11th'],
18
+ [12, '12th'],
19
+ [13, '13th'],
20
+ [14, '14th'],
21
+ [15, '15th'],
22
+ [16, '16th'],
23
+ [17, '17th'],
24
+ [18, '18th'],
25
+ [19, '19th'],
26
+ [20, '20th'],
27
+ [21, '21st'],
28
+ [22, '22nd'],
29
+ [23, '23rd'],
30
+ [24, '24th'],
31
+ [25, '25th'],
32
+ [26, '26th'],
33
+ [27, '27th'],
34
+ [28, '28th'],
35
+ [29, '29th']
36
+ ]
37
+
38
+ test_cases.each do |test_case, expected_result|
39
+
40
+ it "should translate #{test_case} to #{expected_result}" do
41
+ test_case.to_ordinal.should eql(expected_result)
42
+ end
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ordinal
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Lumley
9
+ - Andrew Gallagher
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '2.10'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '2.10'
31
+ description: ! "\n Converts a number (e.g. 1) to an ordinal number (e.g. 1st)\n
32
+ \ "
33
+ email:
34
+ - djlumley@me.com
35
+ - kivlor@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - .gitignore
41
+ - Gemfile
42
+ - LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - lib/ordinal.rb
46
+ - lib/ordinal/version.rb
47
+ - ordinal.gemspec
48
+ - spec/ordinal_spec.rb
49
+ homepage: http://github.com/davidlumley/ordinal
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Converts a number (e.g. 1) to an ordinal number (e.g. 1st)
73
+ test_files:
74
+ - spec/ordinal_spec.rb