Reputation: 43
I am using carr/phone gem for formatting phone numbers. I set default country code like this.
Phoner::Phone.default_country_code = '49'
and when I want to create an object
normalized_number = Phoner::Phone.new(:number => number, :area_code => area, :country_code => intl)
I get an error:
Phoner::CountryCodeError: Must enter country code or set default country code
When using .parse I don't get this error but I need an object. Anyone know how to set default_country_code when creating an object? I tried to send :default_country_code param but didn't work.
Upvotes: 0
Views: 271
Reputation: 12320
This is clear that if country_code is nil
. It will throw this error
Please refer https://github.com/carr/phone/blob/1a326c0f344b7dc1b6d39c80b3042620322c71e9/lib/phone.rb#L142
So you can do simply one thing
normalized_number = Phoner::Phone.new(:number => number, :area_code => area, :country_code => intl) unless country_code.nil?
Upvotes: 1