Sha256: 407db855bdd84730f4e7158c29c3370fc4299de4e2fba4eeea8c718b2b81ab9b

Contents?: true

Size: 798 Bytes

Versions: 4

Compression:

Stored size: 798 Bytes

Contents

module PagSeguro
  class Sender
    attr_accessor :name, :email, :phone_ddd, :phone_number
    
    def initialize(options = {})
      @name         = options[:name]
      @email        = options[:email]
      @phone_ddd    = options[:phone_ddd]
      @phone_number = options[:phone_number]
    end
    
    def email
      valid_email? ? @email : nil
    end

    def valid_email?
      @email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i && @email.size <= 60
    end
    
    def name
      return nil unless valid_name?
      @name.gsub(/ +/, " ")[0..49]
    end
    
    def valid_name?
      @name =~ /\S+ +\S+/
    end
    
    def phone_ddd
      @phone_ddd if @phone_ddd =~ /^\d{2}$/
    end
    
    def phone_number
      @phone_number if @phone_number =~/^\d{8,9}$/
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pag_seguro-0.4.1 lib/pag_seguro/sender.rb
pag_seguro-0.4.0 lib/pag_seguro/sender.rb
pag_seguro-0.3.2 lib/pag_seguro/sender.rb
pag_seguro-0.3.1 lib/pag_seguro/sender.rb