hundredth 1.0.1 → 1.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.
- checksums.yaml +4 -4
- data/lib/hundredth.rb +45 -47
- data/lib/hundredth/version.rb +3 -1
- metadata +36 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c137f3496fb4f11a8249042c2801d0463796f817
|
|
4
|
+
data.tar.gz: 62ef207f73a5bbc618558c86ae0bf8065040b88a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9597e21704e201edf6b69e637b70ab9bac1a43d6f0ea52d1b9c5381f848eb82223c41b1726f85e05330a9e14442406ac43e6c8ea2fcff50ba99a73485204a87
|
|
7
|
+
data.tar.gz: 5eabedc01b467fd604979beda8bd6584833de1c376bb3c6d79c1d16d0c1153e33360398c4532fbec0413ca256dbd8a11ece75ffb84f21e613c9d67a6e20a1685
|
data/lib/hundredth.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Writes out ordinals to 100
|
|
1
4
|
class Hundredth
|
|
2
5
|
require 'hundredth/version'
|
|
3
6
|
require 'i18n'
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
I18n.load_path += Dir.glob(File.join(@@gem_root, 'lib/locales/*.yml'))
|
|
8
|
+
I18n.load_path += Dir.glob(File.join(Gem.loaded_specs['hundredth'].full_gem_path, 'lib/locales/*.yml'))
|
|
7
9
|
I18n.backend.load_translations
|
|
8
10
|
I18n.config.enforce_available_locales = true
|
|
9
11
|
I18n.config.default_locale = :en
|
|
@@ -12,17 +14,13 @@ class Hundredth
|
|
|
12
14
|
def ordinal(number, locale = Thread.current[:locale] || I18n.config.default_locale)
|
|
13
15
|
begin
|
|
14
16
|
number = number.to_int
|
|
15
|
-
rescue
|
|
17
|
+
rescue StandardError
|
|
16
18
|
raise HundredthError, I18n.t('hundredth.not_an_integer', number)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
raise HundredthError, I18n.t('hundredth.less_than_one', number)
|
|
21
|
-
end
|
|
21
|
+
raise HundredthError, I18n.t('hundredth.less_than_one', number) if number < 1
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
return beyond100(number, locale)
|
|
25
|
-
end
|
|
23
|
+
return beyond100(number, locale) if number > 100
|
|
26
24
|
|
|
27
25
|
I18n.t 'hundredth.num_' + number.to_s, locale: locale
|
|
28
26
|
end
|
|
@@ -34,57 +32,57 @@ class Hundredth
|
|
|
34
32
|
def default_locale=(value)
|
|
35
33
|
I18n.config.default_locale = value
|
|
36
34
|
end
|
|
37
|
-
end
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
private
|
|
37
|
+
|
|
41
38
|
def beyond100(number, locale)
|
|
42
39
|
case locale.to_s.split('-').first
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
when 'en'
|
|
41
|
+
beyond100_en number
|
|
42
|
+
when 'es'
|
|
43
|
+
raise NotImplementedError
|
|
44
|
+
when 'fr'
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
else
|
|
47
|
+
raise NotImplementedError
|
|
51
48
|
end
|
|
52
49
|
end
|
|
53
50
|
|
|
54
|
-
#
|
|
51
|
+
# Higher ordinals are not often written in words, unless they are round numbers (thousandth,
|
|
52
|
+
# millionth, billionth). They are written using digits and letters as described below. Here are
|
|
53
|
+
# some rules that should be borne in mind.
|
|
54
|
+
#
|
|
55
|
+
# The suffixes -th, -st, -nd and -rd are occasionally written superscript above the number
|
|
56
|
+
# itself.
|
|
57
|
+
#
|
|
58
|
+
# If the tens digit of a number is 1, then write "th" after the number. For example: 13th, 19th,
|
|
59
|
+
# 112th, 9,311th.
|
|
60
|
+
# If the tens digit is not equal to 1, then use the following table:
|
|
61
|
+
# If the units digit is: 0 1 2 3 4 5 6 7 8 9
|
|
62
|
+
# write this after the number th st nd rd th th th th th th
|
|
63
|
+
# For example: 2nd, 7th, 20th, 23rd, 52nd, 135th, 301st.
|
|
64
|
+
# TODO: option to just return the ordinal indicator
|
|
55
65
|
def beyond100_en(number)
|
|
56
|
-
#
|
|
57
|
-
# millionth, billionth). They are written using digits and letters as described below. Here are
|
|
58
|
-
# some rules that should be borne in mind.
|
|
59
|
-
#
|
|
60
|
-
# The suffixes -th, -st, -nd and -rd are occasionally written superscript above the number
|
|
61
|
-
# itself.
|
|
62
|
-
#
|
|
63
|
-
# If the tens digit of a number is 1, then write "th" after the number. For example: 13th, 19th,
|
|
64
|
-
# 112th, 9,311th.
|
|
65
|
-
# If the tens digit is not equal to 1, then use the following table:
|
|
66
|
-
# If the units digit is: 0 1 2 3 4 5 6 7 8 9
|
|
67
|
-
# write this after the number th st nd rd th th th th th th
|
|
68
|
-
# For example: 2nd, 7th, 20th, 23rd, 52nd, 135th, 301st.
|
|
69
|
-
|
|
70
|
-
if (number > 10) && (((number / 10) % 10) == 1)
|
|
71
|
-
return "#{number}th"
|
|
72
|
-
end
|
|
66
|
+
return "#{number}th" if tens_digit_is_a_one(number)
|
|
73
67
|
|
|
74
68
|
case number % 10
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
when 0, 4, 5, 6, 7, 8, 9
|
|
70
|
+
"#{number}th"
|
|
71
|
+
when 1
|
|
72
|
+
"#{number}st"
|
|
73
|
+
when 2
|
|
74
|
+
"#{number}nd"
|
|
75
|
+
when 3
|
|
76
|
+
"#{number}rd"
|
|
83
77
|
end
|
|
84
78
|
end
|
|
79
|
+
|
|
80
|
+
def tens_digit_is_a_one(number)
|
|
81
|
+
(number > 10) && (((number / 10) % 10) == 1)
|
|
82
|
+
end
|
|
85
83
|
end
|
|
86
84
|
end
|
|
87
85
|
|
|
88
86
|
class HundredthError < StandardError
|
|
89
|
-
# just gives a strong named hundredth error
|
|
87
|
+
# just gives a strong named hundredth error
|
|
90
88
|
end
|
data/lib/hundredth/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hundredth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Cavalieri
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: i18n
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '1.1'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '1.1'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,17 +39,17 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '1.6'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: byebug
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
@@ -72,6 +72,34 @@ dependencies:
|
|
|
72
72
|
- - ">="
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
74
|
version: 5.5.1
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rake
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rubocop
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 0.58.2
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: 0.58.2
|
|
75
103
|
description: |
|
|
76
104
|
Writes out 1 to 100 their full ordinal words. 101 and greater are are written out using the number
|
|
77
105
|
followed by the ordinal indicator, e.g. 'st', 'nd', 'rd'.
|
|
@@ -112,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
112
140
|
version: '0'
|
|
113
141
|
requirements: []
|
|
114
142
|
rubyforge_project:
|
|
115
|
-
rubygems_version: 2.
|
|
143
|
+
rubygems_version: 2.6.13
|
|
116
144
|
signing_key:
|
|
117
145
|
specification_version: 4
|
|
118
146
|
summary: writes out ordinal numbers
|