Class: CrmFormatter::Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/crm_formatter/tools.rb

Instance Method Summary collapse

Instance Method Details

#add_space(str) ⇒ Object



65
66
67
68
# File 'lib/crm_formatter/tools.rb', line 65

def add_space(str)
  return unless str.present?
  str = " #{str} "
end

#capitalize_dashes(str) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crm_formatter/tools.rb', line 23

def capitalize_dashes(str)
  return unless str.present?
  if str&.include?('-')
    els = str.split(' ')
    dash_els = els.select { |el| el != '-' && el.include?('-') }

    dash_els.each do |el|
      el_cap = el.split('-').map(&:capitalize).join('-')
      str = str.gsub(el, el_cap)
    end
  end
  str
end

#force_capitalize(str) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/crm_formatter/tools.rb', line 15

def force_capitalize(str)
  return unless str.present?
  str_parts = str.downcase.split(' ')&.each do |el|
    el.capitalize! if el.gsub(/[^ A-Za-z]/, '')&.strip
  end
  str = str_parts&.join(' ')
end

#force_downcase(str) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/crm_formatter/tools.rb', line 51

def force_downcase(str)
  return unless str.present?
  str = add_space(str)

  grab_downs.map do |down|
    str = str.gsub(" #{down.capitalize} ", " #{down} ")
  end
  str = strip_squeeze(str)
end

#force_first_cap(str) ⇒ Object



61
62
63
# File 'lib/crm_formatter/tools.rb', line 61

def force_first_cap(str)
  str = "#{str[0].upcase}#{str[1..-1]}"
end

#force_upcase(str) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/crm_formatter/tools.rb', line 37

def force_upcase(str)
  return unless str.present?
  str = add_space(str)

  grab_ups.map do |up|
    str = str.gsub(" #{up.capitalize},", " #{up}")
    str = str.gsub(" #{up.capitalize}.", " #{up}")
    str = str.gsub(" #{up.capitalize} ", " #{up} ")
    str = str.gsub(" #{up.capitalize}-", " #{up}-")
    str = str.gsub("-#{up.capitalize} ", "-#{up} ")
  end
  str = strip_squeeze(str)
end

#grab_downsObject



75
76
77
# File 'lib/crm_formatter/tools.rb', line 75

def grab_downs
  downs = %w[and as both but either for from in just neither nor of only or out so the to whether with yet]
end

#grab_upsObject



79
80
81
82
83
84
85
86
# File 'lib/crm_formatter/tools.rb', line 79

def grab_ups
  ups = %w[I]
  brands = %w[BMW CDJR CJDR GMC CJD I]
  professional = %w[BA BS MA JD DC PA MD VP SVP EVP CMO CFO CEO]
  states = %w[AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL KS KY LA MA MD MI MN MO NC ND NE NH NJ NM NV NY OH OK PA RI SC SD TN TX UT VA VT WA WI WV WY]
  directions = %w[NE NW SE SW]
  ups = [brands, professional, states, directions].flatten.uniq
end

#letter_case_check(str) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/crm_formatter/tools.rb', line 5

def letter_case_check(str)
  return unless str.present?
  str = force_capitalize(str)
  str = capitalize_dashes(str)
  str = force_upcase(str)
  str = force_downcase(str)
  str = force_first_cap(str)
  str
end

#strip_squeeze(str) ⇒ Object



70
71
72
73
# File 'lib/crm_formatter/tools.rb', line 70

def strip_squeeze(str)
  str = str.squeeze(' ')
  str = str.strip
end