module CountryCodeLite
Constants
- DICTIONARY
- VERSION
Public Class Methods
countries()
click to toggle source
# File lib/country_code_lite.rb, line 61 def countries DICTIONARY.sort { |a, b| b["number"] <=> a["number"] } end
find_by_code(code)
click to toggle source
# File lib/country_code_lite.rb, line 27 def find_by_code(code) entry = DICTIONARY.select do |e| code.upcase == e["code"] end.first if entry Entry.new(entry["name"], entry["en_name"], entry["number"], entry["code"]) else nil end end
find_by_name(name)
click to toggle source
# File lib/country_code_lite.rb, line 13 def find_by_name(name) entries = DICTIONARY.sort { |a, b| b["name"] <=> a["name"] } entry = entries.select do |e| name == e["name"] end.first if entry Entry.new(entry["name"], entry["en_name"], entry["number"], entry["code"]) else nil end end
find_by_number(number)
click to toggle source
# File lib/country_code_lite.rb, line 39 def find_by_number(number) entries = DICTIONARY.sort { |a, b| b["number"] <=> a["number"] } entry = entries.select do |e| number == e["number"] end.first if entry Entry.new(entry["name"], entry["en_name"], entry["number"], entry["code"]) else nil end end
to_number(phone, code, with_plus = true)
click to toggle source
# File lib/country_code_lite.rb, line 53 def to_number(phone, code, with_plus = true) if with_plus "+#{code}#{phone}" else "#{code}#{phone}" end end