Module: CountryCodes
- Extended by:
- CountryCodes
- Included in:
- CountryCodes
- Defined in:
- lib/country_codes.rb,
lib/country_codes/version.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- DICTIONARY =
YAML.load_file(File.(File.join("..", "country_codes", "dictionary.yml"), __FILE__)).freeze
- VERSION =
"0.1.0"
Instance Method Summary collapse
Instance Method Details
#from_phone_number(number) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/country_codes.rb', line 11 def from_phone_number(number) entries = DICTIONARY.sort { |a, b| b['calling_code'] <=> a['calling_code'] } entry = entries.select do |e| number =~ /\+#{e['calling_code']}\d+$/ end.first if entry Entry.new(entry['name'], entry['calling_code'], entry['code']) else nil end end |