Module: Kontact
- Defined in:
- lib/kontact.rb,
lib/kontact/usa.rb,
lib/kontact/brazil.rb,
lib/kontact/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.6.0"
Class Method Summary collapse
- .detect_country ⇒ Object
- .generate(country: :brazil, type: :mobile, formatted: false) ⇒ Object
- .valid?(number, country: :brazil) ⇒ Boolean
- .validate_country(country) ⇒ Object
Class Method Details
.detect_country ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kontact.rb', line 34 def self.detect_country locale = ENV["LANG"] || ENV["LC_ALL"] || ENV["LC_MESSAGES"] || "" case locale.downcase when /pt[-_]br/ :brazil when /en[-_]us/ :usa else :brazil # as a main fallback end end |
.generate(country: :brazil, type: :mobile, formatted: false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/kontact.rb', line 6 def self.generate(country: :brazil, type: :mobile, formatted: false) validate_country(country) case country.to_sym when :brazil Brazil.generate(type: type, formatted: formatted) when :usa USA.generate(formatted: formatted) else raise ArgumentError, "Unsupported country: #{country}" end end |
.valid?(number, country: :brazil) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kontact.rb', line 18 def self.valid?(number, country: :brazil) validate_country(country) raise ArgumentError, "Number can not empty or blank" unless number case country.to_sym when :brazil Brazil.valid?(number) when :usa USA.valid?(number) else raise ArgumentError, "Unsupported country: #{country}" end end |
.validate_country(country) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kontact.rb', line 46 def self.validate_country(country) case country.to_sym when :brazil :brazil when :usa :usa else raise ArgumentError, "Unsupported country: #{country}" end end |