Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/waxx/patch.rb

Instance Method Summary collapse

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/waxx/patch.rb', line 130

def any?
  self != ""
end

#capitalize_allObject Also known as: title_case

Capitalize all words



126
127
128
# File 'lib/waxx/patch.rb', line 126

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()



118
119
120
121
122
123
124
# File 'lib/waxx/patch.rb', line 118

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

#hObject

Escape HTML entities



113
114
115
# File 'lib/waxx/patch.rb', line 113

def h
  gsub(/[&\"<>]/, {'&'=>'&amp;', '"'=>'&quot;', '<'=>'&lt;', '>'=>'&gt;'})
end