Module: Nth::IntMethods
- Defined in:
- lib/nth.rb
Class Method Summary collapse
- .pence_to_pound(int) ⇒ Object
- .penny_to_dollar(int) ⇒ Object
- .to_nth_string(int, comma = true) ⇒ Object
- .to_number_string(int) ⇒ Object
- .to_ordinal_string(int) ⇒ Object
Class Method Details
.pence_to_pound(int) ⇒ Object
737 738 739 740 741 742 743 744 |
# 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) ⇒ Object
729 730 731 732 733 734 735 736 |
# 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) ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
# 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) ⇒ Object
726 727 728 |
# File 'lib/nth.rb', line 726 def self.to_number_string(int) Nth::get_number_name(int, :-) end |
.to_ordinal_string(int) ⇒ Object
723 724 725 |
# File 'lib/nth.rb', line 723 def self.to_ordinal_string(int) Nth::get_ordinal_name(int, :-) end |