Class: Pagseguro::Charge::Amount

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

Overview

Credit card data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Amount

Returns a new instance of Amount.



10
11
12
13
14
# File 'lib/pagseguro/charge/amount.rb', line 10

def initialize(args = {})
  @value = args[:value]
  @currency = args[:currency]
  @summary = args[:summary]
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



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

def currency
  @currency
end

#summaryObject

Returns the value of attribute summary.



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

def summary
  @summary
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.fill_from_json(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/pagseguro/charge/amount.rb', line 22

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

  amount = new
  amount.currency = data["currency"]
  amount.value = data["value"]
  amount.summary = Summary.fill_from_json(data["summary"])
  amount

end

Instance Method Details

#as_json(options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pagseguro/charge/amount.rb', line 33

def as_json(options={})
  {
    value: @value,
    currency: @currency,
    summary: @summary
  }
end

#to_json(*options) ⇒ Object



16
17
18
19
20
# File 'lib/pagseguro/charge/amount.rb', line 16

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