Method: Phonelib::Core#parse

Defined in:
lib/phonelib/core.rb

#parse(phone, passed_country = nil) ⇒ Object

method for parsing phone number. On first run fills @@phone_data with data present in yaml file



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/phonelib/core.rb', line 92

def parse(phone, passed_country = nil)
  load_data

  country = country_or_default_country(passed_country)
  if phone.nil? || country.nil?
    # has to return instance of Phonelib::Phone even if no phone passed
    Phonelib::Phone.new(phone, @@phone_data)
  else
    detected = detect_and_parse_by_country(phone, country)
    if passed_country.nil? && @@default_country && detected.invalid?
      Phonelib::Phone.new(phone, @@phone_data)
    else
      detected
    end
  end
end