Sha256: 79d2df60d8163fe0e99bef3b9b31579da14483cab78612bafb0b9462ad7ef007

Contents?: true

Size: 797 Bytes

Versions: 3

Compression:

Stored size: 797 Bytes

Contents

module Akatus
  class Payer
    include Transferrable
    transferrable_attrs :name, :email

    attr_accessor :addresses, :phones

    def address=(val)
      addresses ? addresses.unshift(val) : (@addresses = [val])
    end

    def address
      addresses[0] if addresses
    end

    def phone=(val)
      phones ? phones.unshift(val) : (@phones = [val])
    end

    def phone
      phones[0] if phones
    end

    def to_payload(include_root = true)
      payload = super(true)

      # Tweak Akatus' weird array format.
      payload['pagador']['enderecos'] = { 'endereco' => addresses.map { |a| a.to_payload(false) } }
      payload['pagador']['telefones'] = { 'telefone' => phones.map { |p| p.to_payload(false) } }

      include_root ? payload : payload.values.first
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
akatus-1.0.2 lib/akatus/payer.rb
akatus-1.0.1 lib/akatus/payer.rb
akatus-1.0.0 lib/akatus/payer.rb