Module: Phonelib::Core
- Included in:
- PhoneValidator, Phonelib
- Defined in:
- lib/phonelib/core.rb
Overview
main module that includes all basic data and methods
Constant Summary collapse
- @@skip_eager_loading =
false
- @@override_phone_data =
nil
- @@additional_regexes =
{}
- @@vanity_conversion =
false
Instance Method Summary collapse
- #add_additional_regex(country, type, national_regex) ⇒ Object
- #additional_regexes ⇒ Object
-
#additional_regexes=(data) ⇒ Object
setter for data file to use.
-
#default_country ⇒ String, ...
getter method for default_country variable.
-
#default_country=(country) ⇒ String, ...
setter method for default_country variable.
- #dump_additional_regexes ⇒ Object
-
#eager_load! ⇒ Object
eagerly initialize the gem, loads data into memory.
-
#extension_separate_symbols ⇒ String
getter method for extension_separate_symbols variable.
-
#extension_separate_symbols=(separator) ⇒ String
setter method for extension_separate_symbols variable.
-
#extension_separator ⇒ String
getter method for extension_separator variable.
-
#extension_separator=(separator) ⇒ String
setter method for extension_separator variable.
-
#ignore_plus ⇒ Boolean
getter for ignore plus flag.
-
#ignore_plus=(ignore_plus) ⇒ Boolean
setter for ignore plus flag.
-
#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.
- #override_phone_data ⇒ Object
-
#override_phone_data=(file_path) ⇒ Object
setter for data file to use.
-
#parse(phone, passed_country = nil) ⇒ Phonelib::Phone
method for parsing phone number.
-
#parse_special ⇒ Boolean
getter for flag for special phone types parsing.
-
#parse_special=(special) ⇒ Boolean
setter for flag for special phone types parsing.
-
#phone_data ⇒ Hash
getter for phone data for other modules of gem, can be used outside.
-
#possible?(phone_number) ⇒ Boolean
method checks if passed phone number is possible.
-
#sanitize_regex ⇒ String
getter for sanitize regex.
-
#sanitize_regex=(regex) ⇒ String
setter for sanitize regex.
- #skip_eager_loading! ⇒ Object
-
#strict_check ⇒ Boolean
getter for strict check flag.
-
#strict_check=(strict) ⇒ Boolean
setter for strict check flag.
-
#strict_double_prefix_check ⇒ Boolean
getter for strict double prefix check flag.
-
#strict_double_prefix_check=(strict) ⇒ Boolean
setter for strict double prefix check flag.
-
#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.
- #vanity_conversion ⇒ Object
-
#vanity_conversion=(value) ⇒ Object
setter for vanity phone numbers chars replacement.
Instance Method Details
#add_additional_regex(country, type, national_regex) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/phonelib/core.rb', line 202 def add_additional_regex(country, type, national_regex) return unless Phonelib::Core::TYPES_DESC.keys.include?(type.to_sym) return unless national_regex.is_a?(String) @@phone_data = @@data_by_country_codes = nil @@additional_regexes[country.to_s.upcase] ||= {} @@additional_regexes[country.to_s.upcase][type] ||= [] @@additional_regexes[country.to_s.upcase][type] << national_regex end |
#additional_regexes ⇒ Object
223 224 225 |
# File 'lib/phonelib/core.rb', line 223 def additional_regexes @@additional_regexes end |
#additional_regexes=(data) ⇒ Object
setter for data file to use
193 194 195 196 197 198 199 200 |
# File 'lib/phonelib/core.rb', line 193 def additional_regexes=(data) return unless data.is_a?(Array) @@additional_regexes = {} data.each do |row| next if row.size != 3 add_additional_regex(*row) end end |
#default_country ⇒ String, ...
getter method for default_country variable
57 58 59 |
# File 'lib/phonelib/core.rb', line 57 def default_country @@default_country end |
#default_country=(country) ⇒ String, ...
setter method for default_country variable
64 65 66 |
# File 'lib/phonelib/core.rb', line 64 def default_country=(country) @@default_country = country end |
#dump_additional_regexes ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/phonelib/core.rb', line 211 def dump_additional_regexes rows = [] @@additional_regexes.each do |country, types| types.each do |type, regexes| regexes.each do |regex| rows << [country, type, regex] end end end rows end |
#eager_load! ⇒ Object
eagerly initialize the gem, loads data into memory. not required, initialization is done lazily otherwise, but may be desirable in production enviroments to avoid initialization time on first use.
9 10 11 12 13 |
# File 'lib/phonelib/core.rb', line 9 def eager_load! return if @@skip_eager_loading phone_data phone_ext_data end |
#extension_separate_symbols ⇒ String
getter method for extension_separate_symbols variable
89 90 91 |
# File 'lib/phonelib/core.rb', line 89 def extension_separate_symbols @@extension_separate_symbols end |
#extension_separate_symbols=(separator) ⇒ String
setter method for extension_separate_symbols variable
96 97 98 |
# File 'lib/phonelib/core.rb', line 96 def extension_separate_symbols=(separator) @@extension_separate_symbols = separator end |
#extension_separator ⇒ String
getter method for extension_separator variable
73 74 75 |
# File 'lib/phonelib/core.rb', line 73 def extension_separator @@extension_separator end |
#extension_separator=(separator) ⇒ String
setter method for extension_separator variable
80 81 82 |
# File 'lib/phonelib/core.rb', line 80 def extension_separator=(separator) @@extension_separator = separator end |
#ignore_plus ⇒ Boolean
getter for ignore plus flag
138 139 140 |
# File 'lib/phonelib/core.rb', line 138 def ignore_plus @@ignore_plus end |
#ignore_plus=(ignore_plus) ⇒ Boolean
setter for ignore plus flag
145 146 147 |
# File 'lib/phonelib/core.rb', line 145 def ignore_plus=(ignore_plus) @@ignore_plus = ignore_plus end |
#impossible?(phone_number) ⇒ Boolean
method checks if passed phone number is impossible
441 442 443 |
# File 'lib/phonelib/core.rb', line 441 def impossible?(phone_number) parse(phone_number).impossible? end |
#invalid?(phone_number) ⇒ Boolean
method checks if passed phone number is invalid
427 428 429 |
# File 'lib/phonelib/core.rb', line 427 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
457 458 459 |
# File 'lib/phonelib/core.rb', line 457 def invalid_for_country?(phone_number, country) parse(phone_number, country).invalid_for_country?(country) end |
#override_phone_data ⇒ Object
187 188 189 |
# File 'lib/phonelib/core.rb', line 187 def override_phone_data @@override_phone_data end |
#override_phone_data=(file_path) ⇒ Object
setter for data file to use
183 184 185 |
# File 'lib/phonelib/core.rb', line 183 def override_phone_data=(file_path) @@override_phone_data = file_path end |
#parse(phone, passed_country = nil) ⇒ Phonelib::Phone
method for parsing phone number. On first run fills @@phone_data with data present in yaml file
413 414 415 |
# File 'lib/phonelib/core.rb', line 413 def parse(phone, passed_country = nil) Phonelib::Phone.new phone, passed_country end |
#parse_special ⇒ Boolean
getter for flag for special phone types parsing
106 107 108 |
# File 'lib/phonelib/core.rb', line 106 def parse_special @@parse_special end |
#parse_special=(special) ⇒ Boolean
setter for flag for special phone types parsing
113 114 115 |
# File 'lib/phonelib/core.rb', line 113 def parse_special=(special) @@parse_special = special end |
#phone_data ⇒ Hash
getter for phone data for other modules of gem, can be used outside
22 23 24 |
# File 'lib/phonelib/core.rb', line 22 def phone_data @@phone_data ||= load_data.freeze end |
#possible?(phone_number) ⇒ Boolean
method checks if passed phone number is possible
434 435 436 |
# File 'lib/phonelib/core.rb', line 434 def possible?(phone_number) parse(phone_number).possible? end |
#sanitize_regex ⇒ String
getter for sanitize regex
154 155 156 |
# File 'lib/phonelib/core.rb', line 154 def sanitize_regex @@sanitize_regex end |
#sanitize_regex=(regex) ⇒ String
setter for sanitize regex
161 162 163 |
# File 'lib/phonelib/core.rb', line 161 def sanitize_regex=(regex) @@sanitize_regex = regex.is_a?(String) ? regex : regex.to_s end |
#skip_eager_loading! ⇒ Object
16 17 18 |
# File 'lib/phonelib/core.rb', line 16 def skip_eager_loading! @@skip_eager_loading = true end |
#strict_check ⇒ Boolean
getter for strict check flag
122 123 124 |
# File 'lib/phonelib/core.rb', line 122 def strict_check @@strict_check end |
#strict_check=(strict) ⇒ Boolean
setter for strict check flag
129 130 131 |
# File 'lib/phonelib/core.rb', line 129 def strict_check=(strict) @@strict_check = strict end |
#strict_double_prefix_check ⇒ Boolean
getter for strict double prefix check flag
170 171 172 |
# File 'lib/phonelib/core.rb', line 170 def strict_double_prefix_check @@strict_double_prefix_check end |
#strict_double_prefix_check=(strict) ⇒ Boolean
setter for strict double prefix check flag
177 178 179 |
# File 'lib/phonelib/core.rb', line 177 def strict_double_prefix_check=(strict) @@strict_double_prefix_check = strict end |
#valid?(phone_number) ⇒ Boolean
method checks if passed phone number is valid
420 421 422 |
# File 'lib/phonelib/core.rb', line 420 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
449 450 451 |
# File 'lib/phonelib/core.rb', line 449 def valid_for_country?(phone_number, country) parse(phone_number, country).valid_for_country?(country) end |
#vanity_conversion ⇒ Object
233 234 235 |
# File 'lib/phonelib/core.rb', line 233 def vanity_conversion @@vanity_conversion end |
#vanity_conversion=(value) ⇒ Object
setter for vanity phone numbers chars replacement
229 230 231 |
# File 'lib/phonelib/core.rb', line 229 def vanity_conversion=(value) @@vanity_conversion = value end |