Class: Pagseguro::Charge::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/charge/address.rb

Overview

Credit card data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Address

Returns a new instance of Address.



16
17
18
19
20
21
22
23
24
25
# File 'lib/pagseguro/charge/address.rb', line 16

def initialize(args = {})
  @country = args[:country]
  @region = args[:region]
  @region_code = args[:region_code]
  @city = args[:city]
  @postal_code = args[:postal_code]
  @street = args[:street]
  @number = args[:number]
  @locality = args[:locality]
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def city
  @city
end

#countryObject

Returns the value of attribute country.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def country
  @country
end

#localityObject

Returns the value of attribute locality.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def locality
  @locality
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def number
  @number
end

#postal_codeObject

Returns the value of attribute postal_code.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def postal_code
  @postal_code
end

#regionObject

Returns the value of attribute region.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def region
  @region
end

#region_codeObject

Returns the value of attribute region_code.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def region_code
  @region_code
end

#streetObject

Returns the value of attribute street.



6
7
8
# File 'lib/pagseguro/charge/address.rb', line 6

def street
  @street
end

Class Method Details

.fill_from_json(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pagseguro/charge/address.rb', line 33

def self.fill_from_json(data)
  return if data.nil?

  address = new
  address.country = data["country"]
  address.region = data["region"]
  address.region_code = data["region_code"]
  address.city = data["city"]
  address.postal_code = data["postal_code"]
  address.street = data["street"]
  address.number = data["number"]
  address.locality = data["locality"]
  address
end

Instance Method Details

#as_json(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pagseguro/charge/address.rb', line 48

def as_json(options={})
  {
    country: @country,
    region: @region,
    region_code: @region_code,
    city: @city,
    postal_code: @postal_code,
    street: @street,
    number: @number,
    locality: @locality
  }
end

#to_json(*options) ⇒ Object



27
28
29
30
31
# File 'lib/pagseguro/charge/address.rb', line 27

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end