class Interage::ParserPhone

Constants

ALLOWED_SIZES

Attributes

phone[R]

Public Class Methods

call(phone) click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 9
def self.call(phone)
  new(phone).perform
end
new(phone) click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 13
def initialize(phone)
  @phone = only_numbers(phone).to_i.to_s
end

Public Instance Methods

perform() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 17
def perform
  formatted_phone
end

Private Instance Methods

country_code() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 29
def country_code
  "+#{phone[-13..-12]}" if phone[-13..-12].present?
end
ddd() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 33
def ddd
  "(#{phone[-11..-10]})" if phone[-13..-12].present?
end
formatted_phone() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 25
def formatted_phone
  "#{country_code} #{ddd} #{prefix_phone}-#{sufix_phone}".strip
end
prefix_phone() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 37
def prefix_phone
  phone.size == 8 ? phone[-8..-5] : phone[-9..-5]
end
sufix_phone() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 41
def sufix_phone
  phone[-4..]
end
valid?() click to toggle source
# File lib/interage/parsers/parser_phone.rb, line 45
def valid?
  ALLOWED_SIZES.include?(phone.size)
end