Skip to content

Commit

Permalink
Fix a bug in refined_phone_number method
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Sep 25, 2023
1 parent bcd7483 commit f079e79
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/decidim/helsinki_smsauth/phone_number_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ def country_code_hash
@country_code_hash ||= ::Decidim::HelsinkiSmsauth.country_code
end

def refined_phone_number
def refined_phone_number(phone_number)
country_prefix = country_code_prefix.split("+").last
entry = phone_number.to_s
if entry.start_with?("00")
refine_format(entry.gsub(/\A00/, ""))
refined_phone_number(entry.gsub(/\A00/, ""))
elsif entry.start_with?("+")
refined_phone_number(entry.gsub(/\A\+/, ""))
elsif entry.start_with?("0")
entry.gsub(/\A0/, "")
elsif entry.match?(/\A#{country_prefix}/)
entry.gsub(/\A#{country_prefix}/, "")
refined_phone_number(entry.gsub(/\A#{country_prefix}/, ""))
else
entry
end
Expand Down

0 comments on commit f079e79

Please sign in to comment.