Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- waxx/patch.rb
Instance Method Summary collapse
-
#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object
Convert a string to a number and format See Numeric.f().
-
#h ⇒ Object
Escape HTML entities.
Instance Method Details
#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object
Convert a string to a number and format See Numeric.f()
103 104 105 106 107 108 109 |
# File 'waxx/patch.rb', line 103 def f(size=2, zero_as="", t=",", d=".") return zero_as if to_f.zero? num_parts = 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
Escape HTML entities
98 99 100 |
# File 'waxx/patch.rb', line 98 def h gsub(/[&\"<>]/, {'&'=>'&', '"'=>'"', '<'=>'<', '>'=>'>'}) end |