class String
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Public Instance Methods
digitize()
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 19 def digitize gsub(/[^\d]/, "") # "$100,000".digitize # => 100000 end
false?()
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 31 def false? self == "false" end
n2br()
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 11 def n2br strip.gsub("\n", "<br />") end
name_permutations()
click to toggle source
Generates all permutations for first and last name, based on the order of parts A query with 4 words will generate 6 permutations
# File lib/fat_free_crm/core_ext/string.rb, line 37 def name_permutations parts = split(" ") Array.new((parts.size - 1)) do |i| # ["A", "B", "C", "D"] => [["A B C", "D"], ["A B", "C D"], ["A", "B C D"]] [parts[(0..i)].join(" "), parts[(i + 1)..-1].join(" ")] end.each_with_object([]) do |perm, arr| # Search both [first, last] and [last, first] # e.g. for every ["A B C", "D"], also include ["D", "A B C"] arr << perm arr << perm.reverse arr end end
to_url()
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 23 def to_url match?(%r{^https?://}) ? self : "http://#{self}" end
true?()
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 27 def true? self == "true" end
wrap(prefix, suffix = prefix)
click to toggle source
# File lib/fat_free_crm/core_ext/string.rb, line 15 def wrap(prefix, suffix = prefix) prefix + self + suffix end