lib/phonelib/core.rb in phonelib-0.2.5 vs lib/phonelib/core.rb in phonelib-0.2.6
- old
+ new
@@ -59,19 +59,31 @@
NATIONAL_PREFIX = :national_prefix
# National prefix rule key
NATIONAL_PREFIX_RULE = :national_prefix_formatting_rule
# Country code key
COUNTRY_CODE = :country_code
+ # Leading digits key
+ LEADING_DIGITS = :leading_digits
+ # International prefix key
+ INTERNATIONAL_PREFIX = :international_prefix
+ # Main country for code key
+ MAIN_COUNTRY_FOR_CODE = :main_country_for_code
+ # Types key
+ TYPES = :types
+ # Formats key
+ FORMATS = :formats
+ # Pattern key
+ PATTERN = :pattern
# Default number formatting data hash
DEFAULT_NUMBER_FORMAT = {
pattern: '(\\d+)(\\d{3})(\\d{4})',
format: '$1 $2 $3'
}
# hash of all phone types with human representation
- TYPES = {
+ TYPES_DESC = {
general_desc: 'General Pattern',
premium_rate: 'Premium Rate',
toll_free: 'Toll Free',
shared_cost: 'Shared Cost',
voip: 'VoIP',
@@ -154,11 +166,11 @@
# Get Phone instance for provided phone with country specified
def detect_and_parse_by_country(phone, country)
detected = @@phone_data.find { |data| data[:id] == country }
if detected
phone = convert_phone_to_e164(phone,
- detected[:country_code],
- detected[:national_prefix])
+ detected[Core::COUNTRY_CODE],
+ detected[Core::NATIONAL_PREFIX])
end
Phonelib::Phone.new(phone, [detected])
end
# Create phone representation in e164 format