module Nth::IntMethods

Public Class Methods

pence_to_pound(int) click to toggle source
# File lib/nth.rb, line 737
def self.pence_to_pound(int)
  neg = int.negative? ? "minas " : ""
  int = int.abs
  pounds, pence = int.divmod 100
  ps = pounds == 1 ? "" : "s"
  pp = pence == 1 ? " penny" : " pence"
  return neg + to_number_string(pounds) + " pound#{ps} and " + to_number_string(pence) + pp
end
penny_to_dollar(int) click to toggle source
# File lib/nth.rb, line 729
def self.penny_to_dollar(int)
  neg = int.negative? ? "minas " : ""
  int = int.abs
  dollars, cents = int.divmod 100
  ds = dollars == 1 ? "" : "s"
  cs = cents == 1 ? " cent" : " cents"
  return neg + to_number_string(dollars) + " dollar#{ds} and " + to_number_string(cents) + cs
end
to_nth_string(int, comma=true) click to toggle source
# File lib/nth.rb, line 704
def self.to_nth_string(int, comma=true)
  # 0th, 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th
  pre = int.negative? ? "-" : ""
  int = int.abs
  teen = int % 100
  if comma
    str = int.to_s.reverse.scan(/\d{1,3}/).join(',').reverse
  else
    str = int.to_s
  end
  if (teen >= 4) && (teen <= 19)
    return pre + str + "th"
  end
  ones = int % 10
  return (pre + str + "st") if ones == 1
  return (pre + str + "nd") if ones == 2
  return (pre + str + "rd") if ones == 3
  return pre + str + "th"
end
to_number_string(int) click to toggle source
# File lib/nth.rb, line 726
def self.to_number_string(int)
  Nth::get_number_name(int, :-)
end
to_ordinal_string(int) click to toggle source
# File lib/nth.rb, line 723
def self.to_ordinal_string(int)
  Nth::get_ordinal_name(int, :-)
end