module Picpay::Buyer

Attributes

document[RW]
email[RW]
first_name[RW]
last_name[RW]
phone[RW]

Public Instance Methods

data_buyer() click to toggle source
# File lib/picpay/buyer.rb, line 7
def data_buyer
  buyer = {
      "firstName": first_name,
      "lastName": last_name,
      "document": format_document(document),
      "email": email,
      "phone": format_phone(phone)
  }
  buyer
end

Private Instance Methods

format_document(number) click to toggle source
# File lib/picpay/buyer.rb, line 20
def format_document(number)
  # 123.456.789-10
  unless number.nil?
    if (number.size == 11)
      number.to_s.strip.gsub(/[^\d]/, '').sub(/(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3-\\4") unless number.nil?
    else
      number.to_s.strip.gsub(/[^\d]/, '').sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "\\1.\\2.\\3/\\4-\\5") unless number.nil?
    end
  end
end
format_phone(number) click to toggle source
# File lib/picpay/buyer.rb, line 31
def format_phone(number)
  # +55 27 12345-6789
  unless number.nil?
    if (number.size == 17)
      number.to_s.strip.gsub(/[^\d]/, '').sub(/(\d{2})(\d{2})(\d{5})(\d{4})/, "+\\1 \\2 \\3-\\4")
    else
      number.to_s.strip.gsub(/[^\d]/, '').sub(/(\d{2})(\d{2})(\d{4})(\d{4})/, "+\\1 \\2 \\3-\\4")
    end
  end
end