From 1077cccf2954b355f8ab007810d71f65acd3f313 Mon Sep 17 00:00:00 2001 From: Ellie Peterson Date: Tue, 26 Sep 2023 13:53:07 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Programmatically=20determine=20?= =?UTF-8?q?long=5Fform=20for=20en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ordinalize_full.rb | 61 +++++++++- lib/ordinalize_full/locales/en.yml | 172 ++++++++++++----------------- spec/ordinalize_full_spec.rb | 19 +++- 3 files changed, 145 insertions(+), 107 deletions(-) diff --git a/lib/ordinalize_full.rb b/lib/ordinalize_full.rb index a9cf86a..f199935 100644 --- a/lib/ordinalize_full.rb +++ b/lib/ordinalize_full.rb @@ -35,7 +35,11 @@ def ordinalize_in_full(gender: :masculine, plurality: :singular) value else - I18n.t("ordinalize_full.n_#{self}", throw: true) + begin + integer_to_long_form_ordinal + rescue ArgumentError + I18n.t("ordinalize_full.n_#{self}", throw: true) + end end rescue ArgumentError raise NotImplementedError, "Unknown locale #{I18n.locale}" @@ -83,4 +87,59 @@ def ordinalize_in_short(gender: :masculine, plurality: :singular) [self, suffix].join end + + + # Build the long form of a given number. In this context, it is used for every digit except the last two. + # @param number [Integer] - A number to write in long form + # @return [String] - The long form of a number + def number_to_word(number) + + if number == 0 + I18n.t("long_form.simple.ones.n_0", throw: true) + elsif number < 20 + I18n.t("long_form.simple.ones.n_#{number}", throw: true) + elsif number < 100 + "#{I18n.t("long_form.simple.tens.n_#{(number / 10)}", throw: true)}#{(number % 10 == 0) ? "" : "-#{I18n.t("long_form.simple.ones.n_#{number % 10}", throw: true)}"}" + elsif number < 1000 + "#{I18n.t("long_form.simple.ones.n_#{number / 100}", throw: true)} #{I18n.t("long_form.simple.hundred", throw: true)}#{(number % 100 == 0) ? "" : " and #{number_to_word(number % 100)}"}" + else + i = 0 + meow = number + while meow >= 1000 + meow /= 1000 + i += 1 + end + the_one_tenth = number % ((10**(3 * i))) + "#{number_to_word(meow)} #{(i > 0 ? I18n.t("long_form.simple.larger.n_#{i}", throw: true) : "")}#{(the_one_tenth == 0) ? "" : " #{number_to_word(the_one_tenth)}"}" + end + end + + # Builds the ordinalized version of a number. Specific to english. Really only the two least significant digits are ordinalized, and the rest are just in long format + # @param number [Integer] - A number to ordinalize in long form + # @return [String] - The long form of a number as an ordinal + def number_to_ordinal_word(number) + if number == 0 + I18n.t("long_form.ordinal.ones.n_0", throw: true) + elsif number < 20 + I18n.t("long_form.ordinal.ones.n_#{number}", throw: true) + elsif number < 100 && number % 10 == 0 + I18n.t("long_form.ordinal.tens.n_#{(number / 10)}", throw: true) + elsif number < 100 + "#{number_to_word(number - (number % 10))}-#{I18n.t("long_form.ordinal.ones.n_#{number % 10}", throw: true)}" + elsif number >= 100 && number % 100 == 0 + "#{number_to_word(number - (number % 100))}th" + else + "#{number_to_word(number - (number % 100))} and #{number_to_ordinal_word((number % 100))}" + end + end + + # Builds the long form ordinal of an integer + # @return [String] - The long form ordinal of an integer (including negative) + def integer_to_long_form_ordinal + negative = self < 0 ? true : false + + return "#{I18n.t("long_form.negative", throw: true)} #{number_to_ordinal_word(-self)}" if negative + + number_to_ordinal_word(self) + end end diff --git a/lib/ordinalize_full/locales/en.yml b/lib/ordinalize_full/locales/en.yml index d8ee913..03af8e2 100644 --- a/lib/ordinalize_full/locales/en.yml +++ b/lib/ordinalize_full/locales/en.yml @@ -1,102 +1,72 @@ en: - ordinalize_full: - n_1: first - n_2: second - n_3: third - n_4: fourth - n_5: fifth - n_6: sixth - n_7: seventh - n_8: eighth - n_9: ninth - n_10: tenth - n_11: eleventh - n_12: twelfth - n_13: thirteenth - n_14: fourteenth - n_15: fifteenth - n_16: sixteenth - n_17: seventeenth - n_18: eighteenth - n_19: nineteenth - n_20: twentieth - n_21: twenty first - n_22: twenty second - n_23: twenty third - n_24: twenty fourth - n_25: twenty fifth - n_26: twenty sixth - n_27: twenty seventh - n_28: twenty eighth - n_29: twenty ninth - n_30: thirtieth - n_31: thirty first - n_32: thirty second - n_33: thirty third - n_34: thirty fourth - n_35: thirty fifth - n_36: thirty sixth - n_37: thirty seventh - n_38: thirty eighth - n_39: thirty ninth - n_40: fortieth - n_41: forty first - n_42: forty second - n_43: forty third - n_44: forty fourth - n_45: forty fifth - n_46: forty sixth - n_47: forty seventh - n_48: forty eighth - n_49: forty ninth - n_50: fiftieth - n_51: fifty first - n_52: fifty second - n_53: fifty third - n_54: fifty fourth - n_55: fifty fifth - n_56: fifty sixth - n_57: fifty seventh - n_58: fifty eighth - n_59: fifty ninth - n_60: sixtieth - n_61: sixty first - n_62: sixty second - n_63: sixty third - n_64: sixty fourth - n_65: sixty fifth - n_66: sixty sixth - n_67: sixty seventh - n_68: sixty eighth - n_69: sixty ninth - n_70: seventieth - n_71: seventy first - n_72: seventy second - n_73: seventy third - n_74: seventy fourth - n_75: seventy fifth - n_76: seventy sixth - n_77: seventy seventh - n_78: seventy eighth - n_79: seventy ninth - n_80: eightieth - n_81: eighty first - n_82: eighty second - n_83: eighty third - n_84: eighty fourth - n_85: eighty fifth - n_86: eighty sixth - n_87: eighty seventh - n_88: eighty eighth - n_89: eighty ninth - n_90: ninetieth - n_91: ninety first - n_92: ninety second - n_93: ninety third - n_94: ninety fourth - n_95: ninety fifth - n_96: ninety sixth - n_97: ninety seventh - n_98: ninety eighth - n_99: ninety ninth - n_100: one hundredth + long_form: + negative: Negative + simple: + ones: + n_0: Zero + n_1: One + n_2: Two + n_3: Three + n_4: Four + n_5: Five + n_6: Six + n_7: Seven + n_8: Eight + n_9: Nine + n_10: Ten + n_11: Eleven + n_12: Twelve + n_13: Thirteen + n_14: Fourteen + n_15: Fifteen + n_16: Sixteen + n_17: Seventeen + n_18: Eighteen + n_19: Nineteen + tens: + n_2: Twenty + n_3: Thirty + n_4: Forty + n_5: Fifty + n_6: Sixty + n_7: Seventy + n_8: Eighty + n_9: Ninety + hundred: Hundred + larger: + n_0: "" + n_1: Thousand + n_2: Million + n_3: Billion + n_4: Trillion + ordinal: + ones: + n_0: Zeroth + n_1: First + n_2: Second + n_3: Third + n_4: Fourth + n_5: Fifth + n_6: Sixth + n_7: Seventh + n_8: Eighth + n_9: Ninth + n_10: Tenth + n_11: Eleventh + n_12: Twelfth + n_13: Thirteenth + n_14: Fourteenth + n_15: Fifteenth + n_16: Sixteenth + n_17: Seventeenth + n_18: Eigthteenth + n_19: Nineteenth + tens: + n_2: Twentieth + n_3: Thirtieth + n_4: Fortieth + n_5: Fiftieth + n_6: Sixtieth + n_7: Seventieth + n_8: Eightieth + n_9: Ninetieth diff --git a/spec/ordinalize_full_spec.rb b/spec/ordinalize_full_spec.rb index fe78c0a..1e2f24b 100644 --- a/spec/ordinalize_full_spec.rb +++ b/spec/ordinalize_full_spec.rb @@ -7,11 +7,20 @@ context "with the default locale (:en)" do before { I18n.locale = :en } - specify { expect(1.ordinalize_in_full).to eq("first") } - specify { expect(42.ordinalize_in_full).to eq("forty second") } + specify { expect(1.ordinalize_in_full).to eq("First") } + specify { expect(42.ordinalize_in_full).to eq("Forty-Second") } + specify { expect(2023.ordinalize_in_full).to eq("Two Thousand and Twenty-Third") } + specify { expect(2147483647.ordinalize_in_full).to eq("Two Billion One Hundred and Forty-Seven Million Four Hundred and Eighty-Three Thousand Six Hundred and Forty-Seventh") } + + it "converts any number" do + rand = Random.new + 10.times do + expect { rand(1000000).ordinalize_in_full }.not_to raise_error + end + end - it "raises with unknown numbers" do - expect { 101.ordinalize_in_full }.to raise_error(NotImplementedError) + it "handles negatives too" do + expect(-273.ordinalize_in_full).to eq("Negative Two Hundred and Seventy-Third") end end @@ -53,7 +62,7 @@ context "with the default locale (:en)" do before { I18n.locale = :en } - specify { expect(1.ordinalize(in_full: true)).to eq("first") } + specify { expect(1.ordinalize(in_full: true)).to eq("First") } specify { expect(1.ordinalize(in_full: false)).to eq("1st") } end From 40bf157f0b806288fb99e571ef70c7a6ed36f084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Wed, 27 Sep 2023 01:51:57 +0000 Subject: [PATCH 2/4] Fix Rubocop violations Split long lines for better readability. --- .rubocop.yml | 21 ++------ lib/ordinalize_full.rb | 102 +++++++++++++++++++---------------- ordinalize_full.gemspec | 2 +- spec/ordinalize_full_spec.rb | 5 +- 4 files changed, 63 insertions(+), 67 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cd68a79..98f6e2c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,32 +6,17 @@ AllCops: TargetRubyVersion: 3.0 NewCops: enable +Gemspec/DevelopmentDependencies: + Enabled: false + Metrics: Enabled: false Layout/AccessModifierIndentation: EnforcedStyle: outdent -Layout/CaseIndentation: - Enabled: false - -Layout/EndAlignment: - Enabled: false - -Layout/EmptyLinesAroundArguments: - Enabled: false - -Layout/LineLength: - Enabled: false - Style/Alias: EnforcedStyle: prefer_alias_method -Style/Documentation: - Enabled: false - Style/StringLiterals: EnforcedStyle: double_quotes - -Style/SpecialGlobalVars: - Enabled: false diff --git a/lib/ordinalize_full.rb b/lib/ordinalize_full.rb index f199935..f386479 100644 --- a/lib/ordinalize_full.rb +++ b/lib/ordinalize_full.rb @@ -2,6 +2,7 @@ require "i18n" +# Main module module OrdinalizeFull I18n.load_path += Dir[File.join(__dir__, "ordinalize_full/locales/*.yml")] @@ -51,57 +52,64 @@ def ordinalize_in_full(gender: :masculine, plurality: :singular) def ordinalize_in_short(gender: :masculine, plurality: :singular) abs_number = to_i.abs - suffix = case I18n.locale - when :en - if (11..13).cover?(abs_number % 100) - "th" - else - case abs_number % 10 - when 1 then "st" - when 2 then "nd" - when 3 then "rd" - else "th" + suffix = \ + case I18n.locale + when :en + if (11..13).cover?(abs_number % 100) + "th" + else + case abs_number % 10 + when 1 then "st" + when 2 then "nd" + when 3 then "rd" + else "th" + end + end + when :fr + self == 1 ? "er" : "ème" + when :it + "°" + when :nl + [8, 1, 0].include?(self % 100) || self % 100 > 19 ? "ste" : "de" + when :es + value = ordinalize_in_full(gender: gender, plurality: plurality) + + if value.end_with?("er") + ".ᵉʳ" + elsif value.end_with?("a") + ".ᵃ" + elsif value.end_with?("o") + ".ᵒ" + elsif value.end_with?("os") + ".ᵒˢ" + elsif value.end_with?("as") + ".ᵃˢ" end end - when :fr - self == 1 ? "er" : "ème" - when :it - "°" - when :nl - [8, 1, 0].include?(self % 100) || self % 100 > 19 ? "ste" : "de" - when :es - value = ordinalize_in_full(gender: gender, plurality: plurality) - - if value.end_with?("er") - ".ᵉʳ" - elsif value.end_with?("a") - ".ᵃ" - elsif value.end_with?("o") - ".ᵒ" - elsif value.end_with?("os") - ".ᵒˢ" - elsif value.end_with?("as") - ".ᵃˢ" - end - end [self, suffix].join end - # Build the long form of a given number. In this context, it is used for every digit except the last two. # @param number [Integer] - A number to write in long form # @return [String] - The long form of a number def number_to_word(number) - - if number == 0 + if number.zero? I18n.t("long_form.simple.ones.n_0", throw: true) elsif number < 20 I18n.t("long_form.simple.ones.n_#{number}", throw: true) elsif number < 100 - "#{I18n.t("long_form.simple.tens.n_#{(number / 10)}", throw: true)}#{(number % 10 == 0) ? "" : "-#{I18n.t("long_form.simple.ones.n_#{number % 10}", throw: true)}"}" + [ + I18n.t("long_form.simple.tens.n_#{number / 10}", throw: true), + (number % 10).zero? ? "" : "-#{I18n.t("long_form.simple.ones.n_#{number % 10}", throw: true)}" + ].join elsif number < 1000 - "#{I18n.t("long_form.simple.ones.n_#{number / 100}", throw: true)} #{I18n.t("long_form.simple.hundred", throw: true)}#{(number % 100 == 0) ? "" : " and #{number_to_word(number % 100)}"}" + [ + I18n.t("long_form.simple.ones.n_#{number / 100}", throw: true), + " ", + I18n.t("long_form.simple.hundred", throw: true), + (number % 100).zero? ? "" : " and #{number_to_word(number % 100)}" + ].join else i = 0 meow = number @@ -110,23 +118,29 @@ def number_to_word(number) i += 1 end the_one_tenth = number % ((10**(3 * i))) - "#{number_to_word(meow)} #{(i > 0 ? I18n.t("long_form.simple.larger.n_#{i}", throw: true) : "")}#{(the_one_tenth == 0) ? "" : " #{number_to_word(the_one_tenth)}"}" + [ + number_to_word(meow), + " ", + i.positive? ? I18n.t("long_form.simple.larger.n_#{i}", throw: true) : "", + the_one_tenth.zero? ? "" : " #{number_to_word(the_one_tenth)}" + ].join end end - # Builds the ordinalized version of a number. Specific to english. Really only the two least significant digits are ordinalized, and the rest are just in long format + # Builds the ordinalized version of a number. Specific to english. Really only the two least significant digits are + # ordinalized, and the rest are just in long format # @param number [Integer] - A number to ordinalize in long form # @return [String] - The long form of a number as an ordinal def number_to_ordinal_word(number) - if number == 0 + if number.zero? I18n.t("long_form.ordinal.ones.n_0", throw: true) elsif number < 20 I18n.t("long_form.ordinal.ones.n_#{number}", throw: true) - elsif number < 100 && number % 10 == 0 - I18n.t("long_form.ordinal.tens.n_#{(number / 10)}", throw: true) + elsif number < 100 && (number % 10).zero? + I18n.t("long_form.ordinal.tens.n_#{number / 10}", throw: true) elsif number < 100 "#{number_to_word(number - (number % 10))}-#{I18n.t("long_form.ordinal.ones.n_#{number % 10}", throw: true)}" - elsif number >= 100 && number % 100 == 0 + elsif number >= 100 && (number % 100).zero? "#{number_to_word(number - (number % 100))}th" else "#{number_to_word(number - (number % 100))} and #{number_to_ordinal_word((number % 100))}" @@ -136,9 +150,7 @@ def number_to_ordinal_word(number) # Builds the long form ordinal of an integer # @return [String] - The long form ordinal of an integer (including negative) def integer_to_long_form_ordinal - negative = self < 0 ? true : false - - return "#{I18n.t("long_form.negative", throw: true)} #{number_to_ordinal_word(-self)}" if negative + return "#{I18n.t('long_form.negative', throw: true)} #{number_to_ordinal_word(-self)}" if negative? number_to_ordinal_word(self) end diff --git a/ordinalize_full.gemspec b/ordinalize_full.gemspec index 6ed7b0f..a473eb2 100644 --- a/ordinalize_full.gemspec +++ b/ordinalize_full.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/infertux/ordinalize_full" spec.license = "MIT" - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.require_paths = ["lib"] diff --git a/spec/ordinalize_full_spec.rb b/spec/ordinalize_full_spec.rb index 1e2f24b..3799e99 100644 --- a/spec/ordinalize_full_spec.rb +++ b/spec/ordinalize_full_spec.rb @@ -10,12 +10,11 @@ specify { expect(1.ordinalize_in_full).to eq("First") } specify { expect(42.ordinalize_in_full).to eq("Forty-Second") } specify { expect(2023.ordinalize_in_full).to eq("Two Thousand and Twenty-Third") } - specify { expect(2147483647.ordinalize_in_full).to eq("Two Billion One Hundred and Forty-Seven Million Four Hundred and Eighty-Three Thousand Six Hundred and Forty-Seventh") } + specify { expect(2_147_483_647.ordinalize_in_full).to eq("Two Billion One Hundred and Forty-Seven Million Four Hundred and Eighty-Three Thousand Six Hundred and Forty-Seventh") } # rubocop:disable Layout/LineLength it "converts any number" do - rand = Random.new 10.times do - expect { rand(1000000).ordinalize_in_full }.not_to raise_error + expect { rand(1_000_000).ordinalize_in_full }.not_to raise_error end end From 55410a35f4489a12ea36c6d8293e909c60f22eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Wed, 27 Sep 2023 01:52:54 +0000 Subject: [PATCH 3/4] Remove Cane since Rubocop superseded it --- Rakefile | 9 +-------- ordinalize_full.gemspec | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Rakefile b/Rakefile index 28aa196..c40ff22 100644 --- a/Rakefile +++ b/Rakefile @@ -10,11 +10,4 @@ end require "rubocop/rake_task" RuboCop::RakeTask.new -require "cane/rake_task" -Cane::RakeTask.new do |t| - t.no_doc = true - t.style_measure = 120 - t.abc_max = 20 -end - -task default: %i[spec rubocop cane] +task default: %i[spec rubocop] diff --git a/ordinalize_full.gemspec b/ordinalize_full.gemspec index a473eb2..716b774 100644 --- a/ordinalize_full.gemspec +++ b/ordinalize_full.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |spec| spec.add_dependency "i18n", "~> 1.8" spec.add_development_dependency "bundler", ">= 1.5" - spec.add_development_dependency "cane" spec.add_development_dependency "rake" spec.add_development_dependency "rspec", "~> 3" spec.add_development_dependency "rubocop" From 4edf5945e8d7feb83416fb67841d7dd9b22fc339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Wed, 27 Sep 2023 01:58:26 +0000 Subject: [PATCH 4/4] Don't capitalize numbers This would not be backward compatible and there isn't specific rules about it in English according to https://www.grammarbook.com/numbers/numbers.asp. https://ruby-doc.org/3.2.2/String.html#method-i-capitalize can be used easily when capitalization is wanted. --- lib/ordinalize_full/locales/en.yml | 124 ++++++++++++++--------------- spec/ordinalize_full_spec.rb | 12 +-- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/lib/ordinalize_full/locales/en.yml b/lib/ordinalize_full/locales/en.yml index 03af8e2..0cdd585 100644 --- a/lib/ordinalize_full/locales/en.yml +++ b/lib/ordinalize_full/locales/en.yml @@ -1,72 +1,72 @@ en: long_form: - negative: Negative + negative: negative simple: ones: - n_0: Zero - n_1: One - n_2: Two - n_3: Three - n_4: Four - n_5: Five - n_6: Six - n_7: Seven - n_8: Eight - n_9: Nine - n_10: Ten - n_11: Eleven - n_12: Twelve - n_13: Thirteen - n_14: Fourteen - n_15: Fifteen - n_16: Sixteen - n_17: Seventeen - n_18: Eighteen - n_19: Nineteen + n_0: zero + n_1: one + n_2: two + n_3: three + n_4: four + n_5: five + n_6: six + n_7: seven + n_8: eight + n_9: nine + n_10: ten + n_11: eleven + n_12: twelve + n_13: thirteen + n_14: fourteen + n_15: fifteen + n_16: sixteen + n_17: seventeen + n_18: eighteen + n_19: nineteen tens: - n_2: Twenty - n_3: Thirty - n_4: Forty - n_5: Fifty - n_6: Sixty - n_7: Seventy - n_8: Eighty - n_9: Ninety - hundred: Hundred + n_2: twenty + n_3: thirty + n_4: forty + n_5: fifty + n_6: sixty + n_7: seventy + n_8: eighty + n_9: ninety + hundred: hundred larger: n_0: "" - n_1: Thousand - n_2: Million - n_3: Billion - n_4: Trillion + n_1: thousand + n_2: million + n_3: billion + n_4: trillion ordinal: ones: - n_0: Zeroth - n_1: First - n_2: Second - n_3: Third - n_4: Fourth - n_5: Fifth - n_6: Sixth - n_7: Seventh - n_8: Eighth - n_9: Ninth - n_10: Tenth - n_11: Eleventh - n_12: Twelfth - n_13: Thirteenth - n_14: Fourteenth - n_15: Fifteenth - n_16: Sixteenth - n_17: Seventeenth - n_18: Eigthteenth - n_19: Nineteenth + n_0: zeroth + n_1: first + n_2: second + n_3: third + n_4: fourth + n_5: fifth + n_6: sixth + n_7: seventh + n_8: eighth + n_9: ninth + n_10: tenth + n_11: eleventh + n_12: twelfth + n_13: thirteenth + n_14: fourteenth + n_15: fifteenth + n_16: sixteenth + n_17: seventeenth + n_18: eigthteenth + n_19: nineteenth tens: - n_2: Twentieth - n_3: Thirtieth - n_4: Fortieth - n_5: Fiftieth - n_6: Sixtieth - n_7: Seventieth - n_8: Eightieth - n_9: Ninetieth + n_2: twentieth + n_3: thirtieth + n_4: fortieth + n_5: fiftieth + n_6: sixtieth + n_7: seventieth + n_8: eightieth + n_9: ninetieth diff --git a/spec/ordinalize_full_spec.rb b/spec/ordinalize_full_spec.rb index 3799e99..93f3b5c 100644 --- a/spec/ordinalize_full_spec.rb +++ b/spec/ordinalize_full_spec.rb @@ -7,10 +7,10 @@ context "with the default locale (:en)" do before { I18n.locale = :en } - specify { expect(1.ordinalize_in_full).to eq("First") } - specify { expect(42.ordinalize_in_full).to eq("Forty-Second") } - specify { expect(2023.ordinalize_in_full).to eq("Two Thousand and Twenty-Third") } - specify { expect(2_147_483_647.ordinalize_in_full).to eq("Two Billion One Hundred and Forty-Seven Million Four Hundred and Eighty-Three Thousand Six Hundred and Forty-Seventh") } # rubocop:disable Layout/LineLength + specify { expect(1.ordinalize_in_full).to eq("first") } + specify { expect(42.ordinalize_in_full).to eq("forty-second") } + specify { expect(2023.ordinalize_in_full).to eq("two thousand and twenty-third") } + specify { expect(2_147_483_647.ordinalize_in_full).to eq("two billion one hundred and forty-seven million four hundred and eighty-three thousand six hundred and forty-seventh") } # rubocop:disable Layout/LineLength it "converts any number" do 10.times do @@ -19,7 +19,7 @@ end it "handles negatives too" do - expect(-273.ordinalize_in_full).to eq("Negative Two Hundred and Seventy-Third") + expect(-273.ordinalize_in_full).to eq("negative two hundred and seventy-third") end end @@ -61,7 +61,7 @@ context "with the default locale (:en)" do before { I18n.locale = :en } - specify { expect(1.ordinalize(in_full: true)).to eq("First") } + specify { expect(1.ordinalize(in_full: true)).to eq("first") } specify { expect(1.ordinalize(in_full: false)).to eq("1st") } end