Class: PagseguroCatcher::Transaction::Shipping

Inherits:
Body
  • Object
show all
Defined in:
lib/pagseguro_catcher/transaction/shipping.rb

Overview

This class is responsable for parsing the shipping values of the xml.

The part that it parsers is the following:

<shipping>
  <address>
    <street>Av. Brig. Faria Lima</street>
    <number>1384</number>
    <complement>5o andar</complement>
    <district>Jardim Paulistano</district>
    <postalCode>01452002</postalCode>
    <city>Sao Paulo</city>
    <state>SP</state>
    <country>BRA</country>
  </address>
  <type>1</type>
  <cost>21.50</cost>
</shipping>

Instance Attribute Summary

Attributes inherited from Body

#body

Instance Method Summary collapse

Methods inherited from Body

#[]

Constructor Details

#initialize(body) ⇒ Shipping

Returns a new instance of Shipping.



24
25
26
# File 'lib/pagseguro_catcher/transaction/shipping.rb', line 24

def initialize(body)
  self.body = body[:shipping]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

method_missing will try to find anything inside the address node

shipping.street # => "Av. Brig. Faria Lima"


48
49
50
51
# File 'lib/pagseguro_catcher/transaction/shipping.rb', line 48

def method_missing(name, *args)
  return self[:address][name] if self.body[:address].has_key?(name.to_sym)
  super
end

Instance Method Details

#costObject

The the shipping cost as a float

shipping.cost # => 21.50


42
43
44
# File 'lib/pagseguro_catcher/transaction/shipping.rb', line 42

def cost
  self[:cost].to_f
end

#human_typeObject

The human readable value for the shipping type

shipping.human_type # => "Encomenda normal (PAC)"


36
37
38
# File 'lib/pagseguro_catcher/transaction/shipping.rb', line 36

def human_type
  SHIPPING_TYPES[self[:type].to_i]
end

#zipObject

Returns the zip number as a string

shipping.zip # => "012345"


30
31
32
# File 'lib/pagseguro_catcher/transaction/shipping.rb', line 30

def zip
  self[:address][:postalCode]
end