Class: ReeNumber::NumberToPhone

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_number/package/ree_number/functions/number_to_phone.rb

Constant Summary collapse

DEFAULT_PHONE_PATTERN =
/(\d{0,3})(\d{3})(\d{4})$/
DEFAULT_AREA_PHONE_PATTERN =
/(\d{1,3})(\d{3})(\d{4}$)/
DEFAULTS =
{
  delimiter: "-"
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(number, **opts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ree_lib/packages/ree_number/package/ree_number/functions/number_to_phone.rb', line 37

def call(number, **opts)
  options = DEFAULTS.merge(opts)
  str = country_code(options[:country_code], options[:delimiter]).dup

  str << convert_to_phone_number(
    number.to_s.strip,
    options[:delimiter],
    options[:area_code],
    options[:pattern]
  )

  str << phone_extension(options[:extension]) if options[:extension]
  str
end