Module: Phonelib::Core
- Included in:
- PhoneValidator
- Defined in:
- lib/phonelib/core.rb
Overview
main module that includes all basic data and methods
Constant Summary collapse
- FILE_MAIN_DATA =
Main data file
'data/phone_data.dat'
- FILE_EXT_DATA =
Extended data file
'data/extended_data.dat'
- GENERAL =
Validation patterns keys constants General pattern for country key
:general_desc
- PREMIUM_RATE =
Freephone line pattern key
:premium_rate
- TOLL_FREE =
Freephone line pattern key
:toll_free
- SHARED_COST =
Shared cost pattern key. The cost of this call is shared between caller and recipient, and is hence typically less than PREMIUM_RATE calls
:shared_cost
- VOIP =
VoIP pattern key. This includes TSoIP (Telephony Service over IP)
:voip
- PERSONAL_NUMBER =
A personal number is associated with a particular person, and may be routed to either a MOBILE or FIXED_LINE number.
:personal_number
- PAGER =
Pager phone number pattern key
:pager
- UAN =
Used for ‘Universal Access Numbers’ or ‘Company Numbers’. They may be further routed to specific offices, but allow one number to be used for a company.
:uan
- VOICEMAIL =
Used for ‘Voice Mail Access Numbers’.
:voicemail
- FIXED_LINE =
Fixed line pattern key
:fixed_line
- MOBILE =
Mobile phone number pattern key
:mobile
- FIXED_OR_MOBILE =
In case MOBILE and FIXED patterns are the same, this type is returned
:fixed_or_mobile
- SHORT_CODE =
Short code
:short_code
- EMERGENCY =
emergency numbers
:emergency
- CARRIER_SPECIFIC =
carrier specific type
:carrier_specific
- SMS_SERVICES =
SMS Services only type
:sms_services
- EXPANDED_EMERGENCY =
expendad emergency type
:expanded_emergency
- NO_INTERNATIONAL_DIALING =
no international dialling type
:no_international_dialling
- CARRIER_SERVICES =
carrier services type
:carrier_services
- DIRECTORY_SERVICES =
directory services
:directory_services
- STANDARD_RATE =
standard rate type
:standard_rate
- CARRIER_SELECTION_CODES =
carrier selection codes
:carrier_selection_codes
- AREA_CODE_OPTIONAL =
area code optional type
:area_code_optional
- VALID_PATTERN =
Internal use keys for validations Valid regex pattern key
:national_number_pattern
- POSSIBLE_PATTERN =
Possible regex pattern key
:possible_number_pattern
- NATIONAL_PREFIX =
National prefix key
:national_prefix
- NATIONAL_PREFIX_FOR_PARSING =
National prefix for parsing key
:national_prefix_for_parsing
- NATIONAL_PREFIX_RULE =
National prefix rule key
:national_prefix_formatting_rule
- COUNTRY_CODE =
Country code key
:country_code
- LEADING_DIGITS =
Leading digits key
:leading_digits
- INTERNATIONAL_PREFIX =
International prefix key
:international_prefix
- MAIN_COUNTRY_FOR_CODE =
Main country for code key
:main_country_for_code
- DOUBLE_COUNTRY_PREFIX_FLAG =
Double country prefix flag key
:double_prefix
- TYPES =
Types key
:types
- FORMATS =
Formats key
:formats
- PATTERN =
Pattern key
:pattern
- DEFAULT_NUMBER_FORMAT =
Default number formatting data hash
{ pattern: '(\\d+)(\\d{3})(\\d{4})', format: '$1 $2 $3' }
- TYPES_DESC =
hash of all phone types with human representation
{ general_desc: 'General Pattern', premium_rate: 'Premium Rate', toll_free: 'Toll Free', shared_cost: 'Shared Cost', voip: 'VoIP', personal_number: 'Personal Number', pager: 'Pager', uan: 'UAN', voicemail: 'VoiceMail', fixed_line: 'Fixed Line', mobile: 'Mobile', fixed_or_mobile: 'Fixed Line or Mobile', short_code: 'Short code', emergency: 'Emergency services', carrier_specific: 'Carrier specific number', sms_services: 'SMS Services only phone', expanded_emergency: 'Expanded emergency', no_international_dialling: 'No International Dialing phone', carrier_services: 'Carrier Services', directory_services: 'Directory Services', standard_rate: 'Standard Rate Destination', carrier_selection_codes: 'Carrier Selection codes', area_code_optional: 'Are code optional' }
- SHORT_CODES =
short codes types keys
[ :short_code, :emergency, :carrier_specific, :sms_services, :expanded_emergency, :no_international_dialling, :carrier_services, :directory_services, :standard_rate, :carrier_selection_codes, :area_code_optional ]
- EXT_PREFIXES =
Extended data prefixes hash key
:prefixes
- EXT_GEO_NAMES =
Extended data geo names array key
:geo_names
- EXT_TIMEZONES =
Extended data timezones array key
:timezones
- EXT_CARRIERS =
Extended data carriers array key
:carriers
- EXT_GEO_NAME_KEY =
Extended data key for geoname in prefixes hash
:g
- EXT_TIMEZONE_KEY =
Extended data key for timezone in prefixes hash
:t
- EXT_CARRIER_KEY =
Extended data key for carrier in prefixes hash
:c
- @@phone_data =
variable will include hash with data for validation
nil
- @@phone_regexp_cache =
used to cache frequently-used regular expressions
{}
- @@phone_ext_data =
variable for storing geo/carrier/timezone data
nil
- @@default_country =
default country for parsing variable setting
nil
- @@extension_separator =
extension separator
';'
- @@extension_separate_symbols =
extension separator symbols for parsing
'#;'
- @@parse_special =
flag identifies whether to use special phone types, like short code
false
Instance Method Summary collapse
-
#default_country ⇒ Object
getter method for default_country variable.
-
#default_country=(country) ⇒ Object
setter method for default_country variable.
-
#extension_separate_symbols ⇒ Object
getter method for extension_separate_symbols variable.
-
#extension_separate_symbols=(separator) ⇒ Object
setter method for extension_separate_symbols variable.
-
#extension_separator ⇒ Object
getter method for extension_separator variable.
-
#extension_separator=(separator) ⇒ Object
setter method for extension_separator variable.
-
#impossible?(phone_number) ⇒ Boolean
method checks if passed phone number is impossible.
-
#invalid?(phone_number) ⇒ Boolean
method checks if passed phone number is invalid.
-
#invalid_for_country?(phone_number, country) ⇒ Boolean
method checks if passed phone number is invalid for provided country.
-
#parse(phone, passed_country = nil) ⇒ Object
method for parsing phone number.
-
#parse_special ⇒ Object
getter for flag for special phone types parsing.
-
#parse_special=(special) ⇒ Object
setter for flag for special phone types parsing.
-
#phone_data ⇒ Object
getter for phone data for other modules of gem, can be used outside.
-
#phone_ext_data ⇒ Object
getter for extended phone data.
-
#phone_regexp_cache ⇒ Object
getter for phone regexp cache (internal use only).
-
#possible?(phone_number) ⇒ Boolean
method checks if passed phone number is possible.
-
#valid?(phone_number) ⇒ Boolean
method checks if passed phone number is valid.
-
#valid_for_country?(phone_number, country) ⇒ Boolean
method checks if passed phone number is valid for provided country.
Instance Method Details
#default_country ⇒ Object
getter method for default_country variable
32 33 34 |
# File 'lib/phonelib/core.rb', line 32 def default_country @@default_country end |
#default_country=(country) ⇒ Object
setter method for default_country variable
37 38 39 |
# File 'lib/phonelib/core.rb', line 37 def default_country=(country) @@default_country = country end |
#extension_separate_symbols ⇒ Object
getter method for extension_separate_symbols variable
58 59 60 |
# File 'lib/phonelib/core.rb', line 58 def extension_separate_symbols @@extension_separate_symbols end |
#extension_separate_symbols=(separator) ⇒ Object
setter method for extension_separate_symbols variable
63 64 65 |
# File 'lib/phonelib/core.rb', line 63 def extension_separate_symbols=(separator) @@extension_separate_symbols = separator end |
#extension_separator ⇒ Object
getter method for extension_separator variable
45 46 47 |
# File 'lib/phonelib/core.rb', line 45 def extension_separator @@extension_separator end |
#extension_separator=(separator) ⇒ Object
setter method for extension_separator variable
50 51 52 |
# File 'lib/phonelib/core.rb', line 50 def extension_separator=(separator) @@extension_separator = separator end |
#impossible?(phone_number) ⇒ Boolean
method checks if passed phone number is impossible
247 248 249 |
# File 'lib/phonelib/core.rb', line 247 def impossible?(phone_number) parse(phone_number).impossible? end |
#invalid?(phone_number) ⇒ Boolean
method checks if passed phone number is invalid
237 238 239 |
# File 'lib/phonelib/core.rb', line 237 def invalid?(phone_number) parse(phone_number).invalid? end |
#invalid_for_country?(phone_number, country) ⇒ Boolean
method checks if passed phone number is invalid for provided country
257 258 259 |
# File 'lib/phonelib/core.rb', line 257 def invalid_for_country?(phone_number, country) parse(phone_number, country).invalid_for_country?(country) end |
#parse(phone, passed_country = nil) ⇒ Object
method for parsing phone number. On first run fills @@phone_data with data present in yaml file
227 228 229 |
# File 'lib/phonelib/core.rb', line 227 def parse(phone, passed_country = nil) Phonelib::Phone.new phone, passed_country end |
#parse_special ⇒ Object
getter for flag for special phone types parsing
71 72 73 |
# File 'lib/phonelib/core.rb', line 71 def parse_special @@parse_special end |
#parse_special=(special) ⇒ Object
setter for flag for special phone types parsing
76 77 78 |
# File 'lib/phonelib/core.rb', line 76 def parse_special=(special) @@parse_special = special end |
#phone_data ⇒ Object
getter for phone data for other modules of gem, can be used outside
8 9 10 |
# File 'lib/phonelib/core.rb', line 8 def phone_data @@phone_data ||= load_data.freeze end |
#phone_ext_data ⇒ Object
getter for extended phone data
24 25 26 |
# File 'lib/phonelib/core.rb', line 24 def phone_ext_data @@phone_ext_data ||= load_ext_data.freeze end |
#phone_regexp_cache ⇒ Object
getter for phone regexp cache (internal use only)
16 17 18 |
# File 'lib/phonelib/core.rb', line 16 def phone_regexp_cache @@phone_regexp_cache end |
#possible?(phone_number) ⇒ Boolean
method checks if passed phone number is possible
242 243 244 |
# File 'lib/phonelib/core.rb', line 242 def possible?(phone_number) parse(phone_number).possible? end |
#valid?(phone_number) ⇒ Boolean
method checks if passed phone number is valid
232 233 234 |
# File 'lib/phonelib/core.rb', line 232 def valid?(phone_number) parse(phone_number).valid? end |
#valid_for_country?(phone_number, country) ⇒ Boolean
method checks if passed phone number is valid for provided country
252 253 254 |
# File 'lib/phonelib/core.rb', line 252 def valid_for_country?(phone_number, country) parse(phone_number, country).valid_for_country?(country) end |