Module: TellIo

Defined in:
lib/tell_io.rb,
lib/countries/usa.rb,
lib/tell_io/version.rb,
lib/countries/brazil.rb,
lib/countries/country.rb

Defined Under Namespace

Modules: Countries Classes: CountryError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.format_phone(phone:, country:) ⇒ Object



19
20
21
22
# File 'lib/tell_io.rb', line 19

def self.format_phone(phone:, country:)
  country_class = get_country_class(country)
  country_class.format(phone)
end

.generate_phone(country:) ⇒ Object



24
25
26
27
# File 'lib/tell_io.rb', line 24

def self.generate_phone(country:)
  country_class = get_country_class(country)
  country_class.generate
end

.get_country_class(country) ⇒ Object



29
30
31
32
33
# File 'lib/tell_io.rb', line 29

def self.get_country_class(country)
  raise CountryError("Country is empty! Please, tell me what's the country") if country.nil?

  Object.const_get("TellIo::Countries::#{country.to_s.capitalize}")
end

.valid_phone?(phone:, country:) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/tell_io.rb', line 12

def self.valid_phone?(phone:, country:)
  country_class = get_country_class(country)
  country_class.valid?(phone)
rescue NameError
  raise CountryError
end