ordinalize_full 1.2.0 → 1.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9c4ec1c859df34e7e1fc4406dc770305b8edacbe
4
- data.tar.gz: 4489967b56b7b24185081858c528ec1b1d273790
2
+ SHA256:
3
+ metadata.gz: af2369654eef3567467eea82fbdf6ef6f27d4cd2fb751d69d909dab0d047d2a9
4
+ data.tar.gz: 6e991c16ef687c7382c5fdcbe948cf6a539c48af9c3e7b1dc02f9a3adf5a7cc3
5
5
  SHA512:
6
- metadata.gz: 28177340ea0e2048af4b6c13b3653e19266331ff1b3a349df2ea05befacbaf9da034e2d075f9d008be9512e3a37f82fa5e77d8e3c6088da13c60998b7dc44123
7
- data.tar.gz: 4fda783b4bcd3e7440c64883e2dfef93056a9dd05bdd31f5ee36c190ddcf9cc4ec2d0f861ab2ca4857d69a7f77abb94aa24a9c24cea5bd1640fc6daa3e00020e
6
+ metadata.gz: 9cb46422080c99bab1666eba0ec07c0941461220af3204febd83bb9f25162734f0fef1271118977ea3e797dcbdbe76aa47c7d769568187f81f2ee449a5a46e8d
7
+ data.tar.gz: 79340703b14bfeedca1edc0b422d57a751b0416a53168ea3abf784a48b8a7dd35526c4d80d4408b9885ac62fe3197f206920f780bb4c5d2b592ef12cfb5102f0
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Metrics:
6
+ Enabled: false
7
+
8
+ Layout/AccessModifierIndentation:
9
+ EnforcedStyle: outdent
10
+
11
+ Layout/CaseIndentation:
12
+ Enabled: false
13
+
14
+ Layout/EndAlignment:
15
+ Enabled: false
16
+
17
+ Layout/EmptyLinesAroundArguments:
18
+ Enabled: false
19
+
20
+ Layout/LineLength:
21
+ Enabled: false
22
+
23
+ Style/Alias:
24
+ EnforcedStyle: prefer_alias_method
25
+
26
+ Style/Documentation:
27
+ Enabled: false
28
+
29
+ Style/StringLiterals:
30
+ EnforcedStyle: double_quotes
31
+
32
+ Style/SpecialGlobalVars:
33
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,7 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1
4
- notifications:
5
- email:
6
- on_success: always
7
- on_failure: always
3
+ - 3.0.0
4
+ - 2.7.2
5
+ - 2.6.6
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in ordinalize_full.gemspec
4
6
  gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Cédric Félizard
1
+ Copyright (c) 2014-2021 Cédric Félizard
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # OrdinalizeFull [![Build Status](https://travis-ci.org/infertux/ordinalize_full.svg?branch=master)](https://travis-ci.org/infertux/ordinalize_full) [![Dependency Status](https://gemnasium.com/infertux/ordinalize_full.svg)](https://gemnasium.com/infertux/ordinalize_full) [![Code Climate](https://codeclimate.com/github/infertux/ordinalize_full.png)](https://codeclimate.com/github/infertux/ordinalize_full)
1
+ # OrdinalizeFull
2
+
3
+ [![Build Status](https://travis-ci.org/infertux/ordinalize_full.svg?branch=master)](https://travis-ci.org/infertux/ordinalize_full)
4
+ [![Gem Version](https://badge.fury.io/rb/ordinalize_full.svg)](https://badge.fury.io/rb/ordinalize_full)
2
5
 
3
6
  Like Rails' [ordinalize](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-ordinalize) method but with the ability to return the ordinal string spelled out in full words such as _"first"_, _"second"_, _"third"_.
4
7
 
@@ -24,6 +27,13 @@ require "ordinalize_full/integer"
24
27
  I18n.locale = :fr
25
28
  42.ordinalize_in_full #=> "quarante-deuxième"
26
29
  42.ordinalize #=> "42ème"
30
+
31
+ I18n.locale = :es
32
+ 14.ordinalize_in_full(gender: :feminine, plurality: :plural) #=> decimocuartas
33
+ 1.ordinalize_in_full #=> primer // default masculine, singular
34
+ 22.ordinalize_in_full(gender: :feminine) #=> vigésima segunda // default singular
35
+ 1.ordinalize #=> 1.ᵉʳ
36
+ 55.ordinalize #=> 55.ᵒ
27
37
  ```
28
38
 
29
39
  ### Without monkey-patching
@@ -40,5 +50,5 @@ MyIntegerLikeClass.new.ordinalize_in_full #=> "forty second"
40
50
  ## Limitations
41
51
 
42
52
  - only works up to 100 (for now)
43
- - locales only available in English, French and Italian (pull requests welcome!)
53
+ - locales only available in English, French, Italian, Spanish, and Dutch (pull requests welcome!)
44
54
 
data/Rakefile CHANGED
@@ -1,8 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
4
 
5
+ require "rspec/core/rake_task"
4
6
  RSpec::Core::RakeTask.new(:spec) do |t|
5
7
  t.ruby_opts = "-w"
6
8
  end
7
9
 
8
- task :default => :spec
10
+ require "rubocop/rake_task"
11
+ RuboCop::RakeTask.new
12
+
13
+ require "cane/rake_task"
14
+ Cane::RakeTask.new do |t|
15
+ t.no_doc = true
16
+ t.style_measure = 120
17
+ t.abc_max = 20
18
+ end
19
+
20
+ task default: %i[spec rubocop cane]
@@ -1,47 +1,86 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "i18n"
2
4
 
3
5
  module OrdinalizeFull
4
6
  I18n.load_path += Dir[File.join(__dir__, "ordinalize_full/locales/*.yml")]
5
7
 
6
- def ordinalize(in_full: false)
7
- in_full ? ordinalize_in_full : ordinalize_in_short
8
+ def ordinalize(in_full: false, gender: :masculine, plurality: :singular)
9
+ if in_full
10
+ ordinalize_in_full(gender: gender, plurality: plurality)
11
+ else
12
+ ordinalize_in_short(gender: gender, plurality: plurality)
13
+ end
8
14
  end
9
15
 
10
- alias_method :ordinalize_full, \
11
- def ordinalize_in_full
12
- begin
16
+ def ordinalize_in_full(gender: :masculine, plurality: :singular)
17
+ case I18n.locale
18
+ when :fr
19
+ value = I18n.t("ordinalize_full.n_#{self}_#{gender}", throw: false, default: "")
20
+ value = I18n.t("ordinalize_full.n_#{self}", throw: true) if value.empty?
21
+ value
22
+ when :es
23
+ value = I18n.t("ordinalize_full.n_#{self}", throw: false, default: "")
24
+
25
+ if value.empty?
26
+ value = [
27
+ I18n.t("ordinalize_full.n_#{(self / 10) * 10}", throw: true),
28
+ I18n.t("ordinalize_full.n_#{self % 10}", throw: true)
29
+ ].join(" ")
30
+ end
31
+
32
+ value = value.split.map { |part| part.chop << "a" }.join(" ") if gender == :feminine
33
+ value << "s" if plurality == :plural
34
+ value = value.chop if value.end_with?("ero")
35
+
36
+ value
37
+ else
13
38
  I18n.t("ordinalize_full.n_#{self}", throw: true)
14
- rescue ArgumentError
15
- raise NotImplementedError, "Unknown locale #{I18n.locale}"
16
39
  end
40
+ rescue ArgumentError
41
+ raise NotImplementedError, "Unknown locale #{I18n.locale}"
17
42
  end
18
43
 
19
- private
44
+ alias_method :ordinalize_full, :ordinalize_in_full
20
45
 
21
- def ordinalize_in_short
22
- abs_number = self.to_i.abs
46
+ private
23
47
 
48
+ def ordinalize_in_short(gender: :masculine, plurality: :singular)
49
+ abs_number = to_i.abs
24
50
  suffix = case I18n.locale
25
51
  when :en
26
- if (11..13).include?(abs_number % 100)
52
+ if (11..13).cover?(abs_number % 100)
27
53
  "th"
28
54
  else
29
55
  case abs_number % 10
30
- when 1; "st"
31
- when 2; "nd"
32
- when 3; "rd"
33
- else "th"
56
+ when 1 then "st"
57
+ when 2 then "nd"
58
+ when 3 then "rd"
59
+ else "th"
34
60
  end
35
61
  end
36
62
  when :fr
37
63
  self == 1 ? "er" : "ème"
38
64
  when :it
39
65
  "°"
40
- else
41
- raise NotImplementedError, "Unknown locale #{I18n.locale}"
66
+ when :nl
67
+ [8, 1, 0].include?(self % 100) || self % 100 > 19 ? "ste" : "de"
68
+ when :es
69
+ value = ordinalize_in_full(gender: gender, plurality: plurality)
70
+
71
+ if value.end_with?("er")
72
+ ".ᵉʳ"
73
+ elsif value.end_with?("a")
74
+ ".ᵃ"
75
+ elsif value.end_with?("o")
76
+ ".ᵒ"
77
+ elsif value.end_with?("os")
78
+ ".ᵒˢ"
79
+ elsif value.end_with?("as")
80
+ ".ᵃˢ"
81
+ end
42
82
  end
43
83
 
44
84
  [self, suffix].join
45
85
  end
46
86
  end
47
-
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ordinalize_full"
2
4
 
3
5
  class Integer
4
6
  prepend OrdinalizeFull
5
7
  end
6
-
@@ -0,0 +1,30 @@
1
+ es:
2
+ ordinalize_full:
3
+ n_1: primero
4
+ n_2: segundo
5
+ n_3: tercero
6
+ n_4: cuarto
7
+ n_5: quinto
8
+ n_6: sexto
9
+ n_7: séptimo
10
+ n_8: octavo
11
+ n_9: noveno
12
+ n_10: décimo
13
+ n_11: undécimo
14
+ n_12: duodécimo
15
+ n_13: decimotercero
16
+ n_14: decimocuarto
17
+ n_15: decimoquinto
18
+ n_16: decimosexto
19
+ n_17: decimoséptimo
20
+ n_18: decimoctavo
21
+ n_19: decimonoveno
22
+ n_20: vigésimo
23
+ n_30: trigésimo
24
+ n_40: cuadragésimo
25
+ n_50: quincuagésimo
26
+ n_60: sexagésimo
27
+ n_70: septuagésimo
28
+ n_80: octogésimo
29
+ n_90: nonagésimo
30
+ n_100: centésimo
@@ -1,6 +1,7 @@
1
1
  fr:
2
2
  ordinalize_full:
3
3
  n_1: premier
4
+ n_1_feminine: première
4
5
  n_2: deuxième
5
6
  n_3: troisième
6
7
  n_4: quatrième
@@ -0,0 +1,34 @@
1
+ nl:
2
+ ordinalize_full:
3
+ n_1: eerste
4
+ n_2: tweede
5
+ n_3: derde
6
+ n_4: vierde
7
+ n_5: vijfde
8
+ n_6: zesde
9
+ n_7: zevende
10
+ n_8: achtste
11
+ n_9: negende
12
+ n_10: tiende
13
+ n_11: elfde
14
+ n_12: twaalfde
15
+ n_13: dertiende
16
+ n_14: veertiende
17
+ n_15: vijftiende
18
+ n_16: zestiende
19
+ n_17: zeventiende
20
+ n_18: achttiende
21
+ n_19: negentiende
22
+ n_20: twintigste
23
+ n_21: eenentwintigste
24
+ n_22: tweeëntwintigste
25
+ n_30: dertigste
26
+ n_40: veertigste
27
+ n_50: vijftigste
28
+ n_60: zestigste
29
+ n_70: zeventigste
30
+ n_80: tachtigste
31
+ n_90: negentigste
32
+ n_100: honderdste
33
+ n_1000: duizendste
34
+ n_1000000: miljoenste
@@ -1,13 +1,14 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = "ordinalize_full"
7
- spec.version = "1.2.0"
8
+ spec.version = "1.6.0"
8
9
  spec.authors = ["Cédric Félizard"]
9
10
  spec.email = ["cedric@felizard.fr"]
10
- spec.summary = %q{Turns a number into an ordinal string such as first, second, third or 1st, 2nd, 3rd.}
11
+ spec.summary = "Turns a number into an ordinal string such as first, second, third or 1st, 2nd, 3rd."
11
12
  spec.description = spec.summary
12
13
  spec.homepage = "https://github.com/infertux/ordinalize_full"
13
14
  spec.license = "MIT"
@@ -17,9 +18,13 @@ Gem::Specification.new do |spec|
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.add_dependency "i18n", ">= 0.6.6"
21
+ spec.required_ruby_version = ">= 2.6.6"
22
+
23
+ spec.add_dependency "i18n", "~> 0.8"
21
24
 
22
25
  spec.add_development_dependency "bundler", ">= 1.5"
26
+ spec.add_development_dependency "cane"
23
27
  spec.add_development_dependency "rake"
24
28
  spec.add_development_dependency "rspec", "~> 3"
29
+ spec.add_development_dependency "rubocop"
25
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ordinalize_full/integer"
2
4
 
3
5
  describe OrdinalizeFull do
@@ -7,18 +9,39 @@ describe OrdinalizeFull do
7
9
 
8
10
  specify { expect(1.ordinalize_in_full).to eq("first") }
9
11
  specify { expect(42.ordinalize_in_full).to eq("forty second") }
12
+
13
+ it "raises with unknown numbers" do
14
+ expect { 101.ordinalize_in_full }.to raise_error(NotImplementedError)
15
+ end
10
16
  end
11
17
 
12
18
  context "with locale = :fr" do
13
19
  before { I18n.locale = :fr }
14
20
 
15
21
  specify { expect(1.ordinalize_in_full).to eq("premier") }
22
+ specify { expect(1.ordinalize_in_full(gender: :feminine)).to eq("première") }
16
23
  specify { expect(42.ordinalize_in_full).to eq("quarante-deuxième") }
17
24
  end
18
25
 
19
- it "raises for unknown locales" do
20
- I18n.locale = :zz
21
- expect { 1.ordinalize_in_full }.to raise_error(NotImplementedError)
26
+ context "with locale = :nl" do
27
+ before { I18n.locale = :nl }
28
+
29
+ specify { expect(1.ordinalize_in_full).to eq("eerste") }
30
+ specify { expect(22.ordinalize_in_full).to eq("tweeëntwintigste") }
31
+ end
32
+
33
+ context "with locale = :es" do
34
+ before { I18n.locale = :es }
35
+
36
+ specify { expect(1.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("primeras") }
37
+ specify { expect(1.ordinalize_in_full).to eq("primer") }
38
+ specify { expect(13.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("decimoterceras") }
39
+ specify { expect(13.ordinalize_in_full).to eq("decimotercer") }
40
+ specify { expect(14.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("decimocuartas") }
41
+ specify { expect(55.ordinalize_in_full).to eq("quincuagésimo quinto") }
42
+ specify { expect(22.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("vigésima segundas") }
43
+ specify { expect(22.ordinalize_in_full(gender: :feminine)).to eq("vigésima segunda") }
44
+ specify { expect(22.ordinalize_in_full(gender: :feminine, plurality: :singular)).to eq("vigésima segunda") }
22
45
  end
23
46
  end
24
47
 
@@ -48,10 +71,23 @@ describe OrdinalizeFull do
48
71
  specify { expect(1.ordinalize(in_full: false)).to eq("1°") }
49
72
  end
50
73
 
51
- it "raises for unknown locales" do
52
- I18n.locale = :zz
53
- expect { 1.ordinalize(in_full: false) }.to raise_error(NotImplementedError)
74
+ context "with locale = :nl" do
75
+ before { I18n.locale = :nl }
76
+
77
+ specify { expect(1.ordinalize(in_full: true)).to eq("eerste") }
78
+ specify { expect(1.ordinalize(in_full: false)).to eq("1ste") }
79
+ end
80
+
81
+ context "with locale = :es" do
82
+ before { I18n.locale = :es }
83
+
84
+ specify { expect(1.ordinalize(gender: :feminine, plurality: :plural)).to eq("1.ᵃˢ") }
85
+ specify { expect(1.ordinalize).to eq("1.ᵉʳ") }
86
+ specify { expect(13.ordinalize(gender: :feminine, plurality: :plural)).to eq("13.ᵃˢ") }
87
+ specify { expect(13.ordinalize).to eq("13.ᵉʳ") }
88
+ specify { expect(14.ordinalize(gender: :feminine, plurality: :plural)).to eq("14.ᵃˢ") }
89
+ specify { expect(55.ordinalize).to eq("55.ᵒ") }
90
+ specify { expect(22.ordinalize(gender: :feminine, plurality: :plural)).to eq("22.ᵃˢ") }
54
91
  end
55
92
  end
56
93
  end
57
-
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordinalize_full
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.6
19
+ version: '0.8'
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: 0.6.6
26
+ version: '0.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cane
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: Turns a number into an ordinal string such as first, second, third or
70
98
  1st, 2nd, 3rd.
71
99
  email:
@@ -75,6 +103,7 @@ extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
105
  - ".gitignore"
106
+ - ".rubocop.yml"
78
107
  - ".travis.yml"
79
108
  - Gemfile
80
109
  - LICENSE.txt
@@ -83,15 +112,17 @@ files:
83
112
  - lib/ordinalize_full.rb
84
113
  - lib/ordinalize_full/integer.rb
85
114
  - lib/ordinalize_full/locales/en.yml
115
+ - lib/ordinalize_full/locales/es.yml
86
116
  - lib/ordinalize_full/locales/fr.yml
87
117
  - lib/ordinalize_full/locales/it.yml
118
+ - lib/ordinalize_full/locales/nl.yml
88
119
  - ordinalize_full.gemspec
89
120
  - spec/ordinalize_full_spec.rb
90
121
  homepage: https://github.com/infertux/ordinalize_full
91
122
  licenses:
92
123
  - MIT
93
124
  metadata: {}
94
- post_install_message:
125
+ post_install_message:
95
126
  rdoc_options: []
96
127
  require_paths:
97
128
  - lib
@@ -99,16 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
130
  requirements:
100
131
  - - ">="
101
132
  - !ruby/object:Gem::Version
102
- version: '0'
133
+ version: 2.6.6
103
134
  required_rubygems_version: !ruby/object:Gem::Requirement
104
135
  requirements:
105
136
  - - ">="
106
137
  - !ruby/object:Gem::Version
107
138
  version: '0'
108
139
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.2.2
111
- signing_key:
140
+ rubygems_version: 3.1.4
141
+ signing_key:
112
142
  specification_version: 4
113
143
  summary: Turns a number into an ordinal string such as first, second, third or 1st,
114
144
  2nd, 3rd.