Class: CrmFormatter::Wrap

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWrap

Returns a new instance of Wrap.



9
10
11
12
# File 'lib/crm_formatter/wrap.rb', line 9

def initialize
  @crm_data = {}
  @global_hash = grab_global_hash
end

Instance Attribute Details

#crm_dataObject

Returns the value of attribute crm_data.



7
8
9
# File 'lib/crm_formatter/wrap.rb', line 7

def crm_data
  @crm_data
end

#global_hashObject

Returns the value of attribute global_hash.



7
8
9
# File 'lib/crm_formatter/wrap.rb', line 7

def global_hash
  @global_hash
end

Instance Method Details

#format_dataObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/crm_formatter/wrap.rb', line 32

def format_data
  return unless @crm_data[:data][:valid_data].any?
  adr_obj = CrmFormatter::Address.new
  phone_obj = CrmFormatter::Phone.new
  web_obj = CrmFormatter::Web.new

  @crm_data[:data][:valid_data].map! do |valid_hash|
    local_hash = @global_hash
    crmf_url_hsh = web_obj.format_url(valid_hash[:url])
    crmf_phone_hsh = phone_obj.validate_phone(valid_hash[:phone])

    adr_hsh = valid_hash.slice(:street, :city, :state, :zip)
    crmf_adr_hsh = adr_obj.format_full_address(adr_hsh)
    local_hash = local_hash.merge(valid_hash)
    local_hash = local_hash.merge(crmf_url_hsh)
    local_hash = local_hash.merge(crmf_phone_hsh)
    local_hash = local_hash.merge(crmf_adr_hsh)
    local_hash
  end
end

#grab_global_hashObject



14
15
16
17
# File 'lib/crm_formatter/wrap.rb', line 14

def grab_global_hash
  keys = %i[row_id act_name street city state zip full_addr phone url street_f city_f state_f zip_f full_addr_f phone_f url_f url_path web_neg address_status phone_status web_status utf_status]
  @global_hash = Hash[keys.map { |a| [a, nil] }]
end

#import_crm_data(args = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/crm_formatter/wrap.rb', line 25

def import_crm_data(args={})
  @crm_data = { stats: nil, data: nil, file_path: nil }
  @crm_data.merge!(args)
  utf_result = Utf8Sanitizer.sanitize(@crm_data)
  @crm_data.merge!(utf_result)
end

#run(args = {}) ⇒ Object



19
20
21
22
23
# File 'lib/crm_formatter/wrap.rb', line 19

def run(args={})
  import_crm_data(args)
  format_data
  @crm_data
end