Sha256: d25c7a362f1e1f017e89961d39bd133d99a1d5e8af8d9c8e9dd6379b3cb5c01c

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

module PagSeguro
  class Shipping
    include ActiveModel::Validations
    
    PAC = 1
    SEDEX = 2
    UNIDENTIFIED = 3
    
    validates_format_of :postal_code, with: /^\d{8}$/, message: " must be an integer with 8 digits", allow_blank: true
    
    attr_accessor :type, :state, :city, :postal_code, :district, :street, :number, :complement, :cost
    
    def initialize(attributes = {})
      @type = attributes[:type]
      @state = attributes[:state]
      @city = attributes[:city]
      @postal_code = attributes[:postal_code]
      @district = attributes[:district]
      @street = attributes[:street]
      @number = attributes[:number]
      @complement = attributes[:complement]
      @cost = attributes[:cost]
    end
    
    def postal_code
      @postal_code if @postal_code.present? && @postal_code.to_s.size == 8
    end
    
    def type
      @type.to_i
    end
    
    def pac?
      PAC == type
    end
    
    def sedex?
      SEDEX == type
    end
    
    def unidentified?
      UNIDENTIFIED == type
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pag_seguro-0.4.1 lib/pag_seguro/shipping.rb
pag_seguro-0.4.0 lib/pag_seguro/shipping.rb
pag_seguro-0.3.2 lib/pag_seguro/shipping.rb
pag_seguro-0.3.1 lib/pag_seguro/shipping.rb
pag_seguro-0.3.0 lib/pag_seguro/shipping.rb
pag_seguro-0.2.3 lib/pag_seguro/shipping.rb
pag_seguro-0.2.2 lib/pag_seguro/shipping.rb
pag_seguro-0.2.1 lib/pag_seguro/shipping.rb
pag_seguro-0.2.0 lib/pag_seguro/shipping.rb
pag_seguro-0.1.9 lib/pag_seguro/shipping.rb
pag_seguro-0.1.8 lib/pag_seguro/shipping.rb
pag_seguro-0.1.7 lib/pag_seguro/shipping.rb