Class: String
- Inherits:
-
Object
- Object
- String
- 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
- #digitize ⇒ Object
- #false? ⇒ Boolean
- #n2br ⇒ Object
-
#name_permutations ⇒ Object
Generates all permutations for first and last name, based on the order of parts A query with 4 words will generate 6 permutations.
- #snakecase ⇒ Object
- #to_url ⇒ Object
- #true? ⇒ Boolean
- #wrap(prefix, suffix = prefix) ⇒ Object
Instance Method Details
#digitize ⇒ Object
21 22 23 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 21 def digitize gsub(/[^\d]/, "") # "$100,000".digitize # => 100000 end |
#false? ⇒ Boolean
41 42 43 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 41 def false? self == "false" end |
#n2br ⇒ Object
11 12 13 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 11 def n2br strip.gsub("\n", "<br />") end |
#name_permutations ⇒ Object
Generates all permutations for first and last name, based on the order of parts A query with 4 words will generate 6 permutations
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 47 def name_permutations parts = self.split(" ") (parts.size - 1).times.map {|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(" ")] }.inject([]) { |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 |
#snakecase ⇒ Object
31 32 33 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 31 def snakecase self.strip.downcase.gsub(/[\s\/]+/, "_") end |
#to_url ⇒ Object
26 27 28 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 26 def to_url self.match(/^https?:\/\//) ? self : "http://" << self end |
#true? ⇒ Boolean
36 37 38 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 36 def true? self == "true" end |
#wrap(prefix, suffix = prefix) ⇒ Object
16 17 18 |
# File 'lib/fat_free_crm/core_ext/string.rb', line 16 def wrap(prefix, suffix = prefix) prefix + self + suffix end |