Class: PagseguroCatcher::Transaction::Shipping
- 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
Instance Method Summary collapse
-
#cost ⇒ Object
The the shipping cost as a float shipping.cost # => 21.50.
-
#human_type ⇒ Object
The human readable value for the shipping type shipping.human_type # => “Encomenda normal (PAC)”.
-
#initialize(body) ⇒ Shipping
constructor
A new instance of Shipping.
-
#method_missing(name, *args) ⇒ Object
method_missing will try to find anything inside the address node shipping.street # => “Av.
-
#zip ⇒ Object
Returns the zip number as a string shipping.zip # => “012345”.
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
#cost ⇒ Object
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_type ⇒ Object
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 |
#zip ⇒ Object
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 |