Skip to content

Commit

Permalink
Refactor refined_phone_number method; Fix format_human method
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Sep 25, 2023
1 parent f079e79 commit 934d387
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions lib/decidim/helsinki_smsauth/phone_number_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def country_code_prefix

def phone_number_parts
@phone_number_parts ||= [].tap do |parts|
number = phone_number.to_s
number = refined_phone_number
parts << number[0..1]
parts << number[2..4]
parts << number[5..-1]
Expand All @@ -45,20 +45,10 @@ def country_code_hash
@country_code_hash ||= ::Decidim::HelsinkiSmsauth.country_code
end

def refined_phone_number(phone_number)
def refined_phone_number
country_prefix = country_code_prefix.split("+").last
entry = phone_number.to_s
if entry.start_with?("00")
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}/)
refined_phone_number(entry.gsub(/\A#{country_prefix}/, ""))
else
entry
end
entry.gsub(/\A((00||\+)#{country_prefix}|0)/, "")
end
end
end
Expand Down

0 comments on commit 934d387

Please sign in to comment.