Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/waxx/patch.rb
Instance Method Summary collapse
-
#capitalize_all ⇒ Object
Capitalize all words.
-
#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
#capitalize_all ⇒ Object
Capitalize all words
123 124 125 |
# File 'lib/waxx/patch.rb', line 123 def capitalize_all split(/[ _]/).map{|l| l.capitalize}.join(' ') end |
#f(size = 2, zero_as = "", t = ",", d = ".") ⇒ Object
Convert a string to a number and format See Numeric.f()
115 116 117 118 119 120 121 |
# File 'lib/waxx/patch.rb', line 115 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
110 111 112 |
# File 'lib/waxx/patch.rb', line 110 def h gsub(/[&\"<>]/, {'&'=>'&', '"'=>'"', '<'=>'<', '>'=>'>'}) end |