Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/fat_free_crm/core_ext/string.rb

Overview

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


Instance Method Summary collapse

Instance Method Details

#digitizeObject



17
18
19
# File 'lib/fat_free_crm/core_ext/string.rb', line 17

def digitize
  gsub(/[^\d]/, "")  # "$100,000".digitize # => 100000
end

#false?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fat_free_crm/core_ext/string.rb', line 29

def false?
  self == "false"
end

#n2brObject



9
10
11
# File 'lib/fat_free_crm/core_ext/string.rb', line 9

def n2br
  strip.gsub("\n", "<br />")
end

#name_permutationsObject

Generates all permutations for first and last name, based on the order of parts A query with 4 words will generate 6 permutations



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fat_free_crm/core_ext/string.rb', line 35

def name_permutations
  parts = split(" ")
  (parts.size - 1).times.map 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.inject([]) do |arr, perm|
    # 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_urlObject



21
22
23
# File 'lib/fat_free_crm/core_ext/string.rb', line 21

def to_url
  match(/^https?:\/\//) ? self : "http://" << self
end

#true?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fat_free_crm/core_ext/string.rb', line 25

def true?
  self == "true"
end

#wrap(prefix, suffix = prefix) ⇒ Object



13
14
15
# File 'lib/fat_free_crm/core_ext/string.rb', line 13

def wrap(prefix, suffix = prefix)
  prefix + self + suffix
end