Module: Paypal::Util

Included in:
Base
Defined in:
lib/paypal/util.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.formatted_amount(x) ⇒ Object



4
5
6
7
# File 'lib/paypal/util.rb', line 4

def self.formatted_amount(x)
  # Thanks @nahi ;)
  sprintf "%0.2f", BigDecimal.new(x.to_s).truncate(2)
end

.to_numeric(x) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/paypal/util.rb', line 9

def self.to_numeric(x)
  if x.to_f == x.to_i
    x.to_i
  else
    x.to_f
  end
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
# File 'lib/paypal/util.rb', line 21

def ==(other)
  instance_variables.all? do |key|
    instance_variable_get(key) == other.instance_variable_get(key)
  end
end

#numeric_attribute?(key) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/paypal/util.rb', line 17

def numeric_attribute?(key)
  !!(key.to_s =~ /(amount|frequency|cycles|paid)/)
end