Module: PaymentRecipes::Utils::Converters

Instance Method Summary collapse

Instance Method Details

#convert_to_money(amount:, currency:) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/payment_recipes/utils/converters.rb', line 20

def convert_to_money(amount:, currency:)
  nil_check(amount, currency) do
    raise Exception, "Money amount must be a String" unless amount.is_a?(String)

    ::Money.new(::BigDecimal.new(amount) * 100, currency)
  end
end

#convert_to_string(target) ⇒ Object


14
15
16
17
18
# File 'lib/payment_recipes/utils/converters.rb', line 14

def convert_to_string(target)
  nil_check(target) do
    target.to_s
  end
end

#convert_to_symbol(target) ⇒ Object


28
29
30
31
32
# File 'lib/payment_recipes/utils/converters.rb', line 28

def convert_to_symbol(target)
  nil_check(target) do
    target.to_sym
  end
end

#convert_to_time(target) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'lib/payment_recipes/utils/converters.rb', line 4

def convert_to_time(target)
  nil_check(target) do
    if defined?(Time.zone)
      Time.zone.parse(target)
    else
      Time.parse(target)
    end
  end
end