ordinalize_full 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1de1ece0fa8a2114293da96d6eb72a94c276f40
4
- data.tar.gz: 6cec03de6f85ca0a1de0a8a6e764941df61ad41c
3
+ metadata.gz: c671e187d1a069f4174f286018ed9d8cf6209cca
4
+ data.tar.gz: bd49581d94bbb514031b2314ad50b1e6ada48edd
5
5
  SHA512:
6
- metadata.gz: 56d602b51f8c9381a2fd3e4f5da1f6f6a2b9f6724d6eed6ebbd9ce823ff35a805fcff5e34e6ecfc45d8f2ef95a2e09966bbad57cbfb2814efee6d622b9b208f8
7
- data.tar.gz: f817ae2f1b47965c8f11d169f6c93d8c2c4e7f6c1dbf891c29b071666f33b3725a11d49b4f493f8c89d12a4768b1bb44a251d8085b84991c853fc9274712494e
6
+ metadata.gz: 4886677f120a33543b12a4a8060677827ae2e5a19792c1a0fb961cb299576443d6f7e00cfdb0eacec8d0e2dbafae331027989e7227022228283e0cfd197f8115
7
+ data.tar.gz: 2717cc55b05711c180c8c45ef2b9998258239d825e7055955c2ee8dc34de141df02a0b596443aab367bd1eb2749d5529a378753bed4d8ea5467c32ea3502c954
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ Metrics:
2
+ Enabled: false
3
+
4
+ Layout/AccessModifierIndentation:
5
+ EnforcedStyle: outdent
6
+
7
+ Layout/AlignParameters:
8
+ Enabled: false
9
+
10
+ Layout/CaseIndentation:
11
+ Enabled: false
12
+
13
+ Lint/EndAlignment:
14
+ Enabled: false
15
+
16
+ Style/Alias:
17
+ EnforcedStyle: prefer_alias_method
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/StringLiterals:
23
+ EnforcedStyle: double_quotes
24
+
25
+ Style/SpecialGlobalVars:
26
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,16 +1,10 @@
1
1
  language: ruby
2
- after_script:
3
- - cane --no-doc
4
2
  rvm:
5
- - 2.1
6
- - 2.2
3
+ - 2.3.4
4
+ - 2.4.1
7
5
  - ruby-head
8
6
  - rbx
9
7
  matrix:
10
8
  allow_failures:
11
9
  - rvm: ruby-head
12
10
  - rvm: rbx
13
- notifications:
14
- email:
15
- on_success: always
16
- on_failure: always
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ordinalize_full.gemspec
4
4
  gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2015 Cédric Félizard
1
+ Copyright (c) 2014-2017 Cédric Félizard
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -24,6 +24,13 @@ require "ordinalize_full/integer"
24
24
  I18n.locale = :fr
25
25
  42.ordinalize_in_full #=> "quarante-deuxième"
26
26
  42.ordinalize #=> "42ème"
27
+
28
+ I18n.locale = :es
29
+ 14.ordinalize_in_full(gender: :feminine, plurality: :plural) #=> decimocuartas
30
+ 1.ordinalize_in_full #=> primer // default masculine, singular
31
+ 22.ordinalize_in_full(gender: :feminine) #=> vigésima segunda // default singular
32
+ 1.ordinalize #=> 1.ᵉʳ
33
+ 55.ordinalize #=> 55.ᵒ
27
34
  ```
28
35
 
29
36
  ### Without monkey-patching
@@ -40,5 +47,5 @@ MyIntegerLikeClass.new.ordinalize_in_full #=> "forty second"
40
47
  ## Limitations
41
48
 
42
49
  - only works up to 100 (for now)
43
- - locales only available in English, French, Italian and Dutch (pull requests welcome!)
50
+ - locales only available in English, French, Italian, Spanish, and Dutch (pull requests welcome!)
44
51
 
data/Rakefile CHANGED
@@ -1,8 +1,18 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
2
 
3
+ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec) do |t|
5
5
  t.ruby_opts = "-w"
6
6
  end
7
7
 
8
- task :default => :spec
8
+ require "rubocop/rake_task"
9
+ RuboCop::RakeTask.new
10
+
11
+ require "cane/rake_task"
12
+ Cane::RakeTask.new do |t|
13
+ t.no_doc = true
14
+ t.style_measure = 120
15
+ t.abc_max = 20
16
+ end
17
+
18
+ task default: %i[spec rubocop cane]
@@ -3,4 +3,3 @@ require "ordinalize_full"
3
3
  class Integer
4
4
  prepend OrdinalizeFull
5
5
  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
@@ -3,34 +3,56 @@ require "i18n"
3
3
  module OrdinalizeFull
4
4
  I18n.load_path += Dir[File.join(__dir__, "ordinalize_full/locales/*.yml")]
5
5
 
6
- def ordinalize(in_full: false)
7
- in_full ? ordinalize_in_full : ordinalize_in_short
6
+ def ordinalize(in_full: false, gender: :masculine, plurality: :singular)
7
+ if in_full
8
+ ordinalize_in_full(gender: gender, plurality: plurality)
9
+ else
10
+ ordinalize_in_short(gender: gender, plurality: plurality)
11
+ end
8
12
  end
9
13
 
10
14
  alias_method :ordinalize_full, \
11
- def ordinalize_in_full
12
- begin
15
+ def ordinalize_in_full(gender: :masculine, plurality: :singular)
16
+ case I18n.locale
17
+ when :es
18
+ value = I18n.t("ordinalize_full.n_#{self}", throw: false, default: "")
19
+
20
+ if value.empty?
21
+ value = [
22
+ I18n.t("ordinalize_full.n_#{(self / 10) * 10}", throw: true),
23
+ I18n.t("ordinalize_full.n_#{self % 10}", throw: true)
24
+ ].join(" ")
25
+ end
26
+
27
+ if gender == :feminine
28
+ value = value.split.map { |part| part.chop << "a" }.join(" ")
29
+ end
30
+
31
+ value << "s" if plurality == :plural
32
+ value = value.chop if value.end_with?("ero")
33
+
34
+ value
35
+ else
13
36
  I18n.t("ordinalize_full.n_#{self}", throw: true)
14
- rescue ArgumentError
15
- raise NotImplementedError, "Unknown locale #{I18n.locale}"
16
37
  end
38
+ rescue ArgumentError
39
+ raise NotImplementedError, "Unknown locale #{I18n.locale}"
17
40
  end
18
41
 
19
42
  private
20
43
 
21
- def ordinalize_in_short
22
- abs_number = self.to_i.abs
23
-
44
+ def ordinalize_in_short(gender: :masculine, plurality: :singular)
45
+ abs_number = to_i.abs
24
46
  suffix = case I18n.locale
25
47
  when :en
26
- if (11..13).include?(abs_number % 100)
48
+ if (11..13).cover?(abs_number % 100)
27
49
  "th"
28
50
  else
29
51
  case abs_number % 10
30
- when 1; "st"
31
- when 2; "nd"
32
- when 3; "rd"
33
- else "th"
52
+ when 1 then "st"
53
+ when 2 then "nd"
54
+ when 3 then "rd"
55
+ else "th"
34
56
  end
35
57
  end
36
58
  when :fr
@@ -39,9 +61,22 @@ private
39
61
  "°"
40
62
  when :nl
41
63
  [8, 1, 0].include?(self % 100) || self % 100 > 19 ? "ste" : "de"
64
+ when :es
65
+ value = ordinalize_in_full(gender: gender, plurality: plurality)
66
+
67
+ if value.end_with?("er")
68
+ ".ᵉʳ"
69
+ elsif value.end_with?("a")
70
+ ".ᵃ"
71
+ elsif value.end_with?("o")
72
+ ".ᵒ"
73
+ elsif value.end_with?("os")
74
+ ".ᵒˢ"
75
+ elsif value.end_with?("as")
76
+ ".ᵃˢ"
77
+ end
42
78
  end
43
79
 
44
80
  [self, suffix].join
45
81
  end
46
82
  end
47
-
@@ -1,13 +1,14 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
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.3.0"
8
+ spec.version = "1.4.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"
@@ -23,4 +24,5 @@ Gem::Specification.new do |spec|
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec", "~> 3"
25
26
  spec.add_development_dependency "cane"
27
+ spec.add_development_dependency "rubocop"
26
28
  end
@@ -26,6 +26,20 @@ describe OrdinalizeFull do
26
26
  specify { expect(1.ordinalize_in_full).to eq("eerste") }
27
27
  specify { expect(22.ordinalize_in_full).to eq("tweeëntwintigste") }
28
28
  end
29
+
30
+ context "with locale = :es" do
31
+ before { I18n.locale = :es }
32
+
33
+ specify { expect(1.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("primeras") }
34
+ specify { expect(1.ordinalize_in_full).to eq("primer") }
35
+ specify { expect(13.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("decimoterceras") }
36
+ specify { expect(13.ordinalize_in_full).to eq("decimotercer") }
37
+ specify { expect(14.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("decimocuartas") }
38
+ specify { expect(55.ordinalize_in_full).to eq("quincuagésimo quinto") }
39
+ specify { expect(22.ordinalize_in_full(gender: :feminine, plurality: :plural)).to eq("vigésima segundas") }
40
+ specify { expect(22.ordinalize_in_full(gender: :feminine)).to eq("vigésima segunda") }
41
+ specify { expect(22.ordinalize_in_full(gender: :feminine, plurality: :singular)).to eq("vigésima segunda") }
42
+ end
29
43
  end
30
44
 
31
45
  describe "#ordinalize_full" do
@@ -60,6 +74,17 @@ describe OrdinalizeFull do
60
74
  specify { expect(1.ordinalize(in_full: true)).to eq("eerste") }
61
75
  specify { expect(1.ordinalize(in_full: false)).to eq("1ste") }
62
76
  end
77
+
78
+ context "with locale = :es" do
79
+ before { I18n.locale = :es }
80
+
81
+ specify { expect(1.ordinalize(gender: :feminine, plurality: :plural)).to eq("1.ᵃˢ") }
82
+ specify { expect(1.ordinalize).to eq("1.ᵉʳ") }
83
+ specify { expect(13.ordinalize(gender: :feminine, plurality: :plural)).to eq("13.ᵃˢ") }
84
+ specify { expect(13.ordinalize).to eq("13.ᵉʳ") }
85
+ specify { expect(14.ordinalize(gender: :feminine, plurality: :plural)).to eq("14.ᵃˢ") }
86
+ specify { expect(55.ordinalize).to eq("55.ᵒ") }
87
+ specify { expect(22.ordinalize(gender: :feminine, plurality: :plural)).to eq("22.ᵃˢ") }
88
+ end
63
89
  end
64
90
  end
65
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordinalize_full
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
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'
83
97
  description: Turns a number into an ordinal string such as first, second, third or
84
98
  1st, 2nd, 3rd.
85
99
  email:
@@ -89,6 +103,7 @@ extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - ".gitignore"
106
+ - ".rubocop.yml"
92
107
  - ".travis.yml"
93
108
  - Gemfile
94
109
  - LICENSE.txt
@@ -97,6 +112,7 @@ files:
97
112
  - lib/ordinalize_full.rb
98
113
  - lib/ordinalize_full/integer.rb
99
114
  - lib/ordinalize_full/locales/en.yml
115
+ - lib/ordinalize_full/locales/es.yml
100
116
  - lib/ordinalize_full/locales/fr.yml
101
117
  - lib/ordinalize_full/locales/it.yml
102
118
  - lib/ordinalize_full/locales/nl.yml
@@ -122,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
138
  version: '0'
123
139
  requirements: []
124
140
  rubyforge_project:
125
- rubygems_version: 2.4.6
141
+ rubygems_version: 2.6.8
126
142
  signing_key:
127
143
  specification_version: 4
128
144
  summary: Turns a number into an ordinal string such as first, second, third or 1st,