ordinalize_full 1.2.1 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d09ede4cebe7628af68020a5b0dd83fece85fdf8
4
- data.tar.gz: 6ac4cac4fdff2d4877cdacf1204861b41ed1d933
2
+ SHA256:
3
+ metadata.gz: 5db56ba1c97a668a502d971c780523694742eb242e582616d9f982f2fe162126
4
+ data.tar.gz: 39f3ffcdf15ec763c63e5fd3c6aefba839964f290b6bfd3bda32525dfb6f18d7
5
5
  SHA512:
6
- metadata.gz: d50191512b2affe24ce8311f89a72396dfa77b6d116fe4261927792a2e8868a8fd87e2d4f20d9b53509a8b020bdf1d95bb5891477b22fbf222cbc57b8689800f
7
- data.tar.gz: 097383b19eec711220ca39293716d99ad92938d426e4816cd2071efad572681888dc03197658669acb0b02b87dc68eb1debe5493cffec680a1e6ad807f84b163
6
+ metadata.gz: a54b9e3f9f04d9dea5e881099b8c150a8af7488f8183933551bdde8281c519e340a33724298b1e8da7e91f61d440313b548faddede3aa8f288936d54313ae179
7
+ data.tar.gz: e4dbf56069ebbdfa4d08498cf36472baa09727b1182c53d707024a35cf538045f9fe2177d713b8bd44b268dbceba26339744e7270287bac62f6bf63daff9c0ab
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, Italian and Dutch (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,36 +1,62 @@
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
@@ -38,12 +64,23 @@ private
38
64
  when :it
39
65
  "°"
40
66
  when :nl
41
- self % 100 == 8 || self % 100 == 1 || self % 100 > 19 || self % 100 == 0 ? "ste" : "de"
42
- else
43
- raise NotImplementedError, "Unknown locale #{I18n.locale}"
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
44
82
  end
45
83
 
46
84
  [self, suffix].join
47
85
  end
48
86
  end
49
-
@@ -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
@@ -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.1"
8
+ spec.version = "2.0.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", "~> 1.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,12 +9,17 @@ 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
 
@@ -23,9 +30,18 @@ describe OrdinalizeFull do
23
30
  specify { expect(22.ordinalize_in_full).to eq("tweeëntwintigste") }
24
31
  end
25
32
 
26
- it "raises for unknown locales" do
27
- I18n.locale = :zz
28
- expect { 1.ordinalize_in_full }.to raise_error(NotImplementedError)
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") }
29
45
  end
30
46
  end
31
47
 
@@ -62,10 +78,16 @@ describe OrdinalizeFull do
62
78
  specify { expect(1.ordinalize(in_full: false)).to eq("1ste") }
63
79
  end
64
80
 
65
- it "raises for unknown locales" do
66
- I18n.locale = :zz
67
- expect { 1.ordinalize(in_full: false) }.to raise_error(NotImplementedError)
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.ᵃˢ") }
68
91
  end
69
92
  end
70
93
  end
71
-
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.1
4
+ version: 2.0.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-11-03 00:00:00.000000000 Z
11
+ date: 2021-03-18 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: '1.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: '1.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,6 +112,7 @@ 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
88
118
  - lib/ordinalize_full/locales/nl.yml
@@ -92,7 +122,7 @@ homepage: https://github.com/infertux/ordinalize_full
92
122
  licenses:
93
123
  - MIT
94
124
  metadata: {}
95
- post_install_message:
125
+ post_install_message:
96
126
  rdoc_options: []
97
127
  require_paths:
98
128
  - lib
@@ -100,16 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
130
  requirements:
101
131
  - - ">="
102
132
  - !ruby/object:Gem::Version
103
- version: '0'
133
+ version: 2.6.6
104
134
  required_rubygems_version: !ruby/object:Gem::Requirement
105
135
  requirements:
106
136
  - - ">="
107
137
  - !ruby/object:Gem::Version
108
138
  version: '0'
109
139
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.4.2
112
- signing_key:
140
+ rubygems_version: 3.1.4
141
+ signing_key:
113
142
  specification_version: 4
114
143
  summary: Turns a number into an ordinal string such as first, second, third or 1st,
115
144
  2nd, 3rd.