Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/waxx/patch.rb
Instance Method Summary collapse
-
#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object
Format a number size: number of decimal places zero_as: will display zero as “” (blank), “-” (dash), etc.
-
#h ⇒ Object
HTML format (self – no escaping needed).
- #ordinal ⇒ Object
Instance Method Details
#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object
Format a number
size: number of decimal places
zero_as: will display zero as "" (blank), "-" (dash), etc.
t: thousands seperator
d: decimal seperator
88 89 90 91 92 93 94 |
# File 'lib/waxx/patch.rb', line 88 def f(size=2, zero_as="", t=",", d=".") return zero_as if zero? num_parts = to_s.split(".") x = num_parts[0].gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{t}") return x if size == 0 x << (d + (num_parts[1].to_s + "0000000")[0,size]) end |
#h ⇒ Object
HTML format (self – no escaping needed)
80 81 82 |
# File 'lib/waxx/patch.rb', line 80 def h self end |
#ordinal ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/waxx/patch.rb', line 95 def ordinal case self % 100 when 11, 12, 13 then "#{self}th" else case self % 10 when 1 then "#{self}st" when 2 then "#{self}nd" when 3 then "#{self}rd" else "#{self}th" end end end |