Class: SpreeCmCommissioner::InternationalMobileFormatter

Inherits:
BaseInteractor
  • Object
show all
Defined in:
app/interactors/spree_cm_commissioner/international_mobile_formatter.rb

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/interactors/spree_cm_commissioner/international_mobile_formatter.rb', line 3

def call
  country_code = context.country_code || 'kh'
  return if context.phone_number.nil?

  mobile_phone = context.phone_number.gsub(/[()\s-]/, '')
  phone = Phonelib.parse(mobile_phone, country_code)

  international = phone.international
  international = international.present? ? international.gsub(/[()\s-]/, '') : nil

  context.formatted_phone_number = international
end