Class: Faker::Invoice
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0) ⇒ Object
Generate random amount between values with 2 decimals.
-
.creditor_reference(legacy_ref = NOT_GIVEN, ref: '') ⇒ Object
International bank slip reference en.wikipedia.org/wiki/Creditor_Reference ref is optional so that we can create unit tests.
-
.reference(legacy_ref = NOT_GIVEN, ref: '') ⇒ Object
Payment references have some rules in certain countries ref is optional so that we can create unit tests.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0) ⇒ Object
Generate random amount between values with 2 decimals
9 10 11 12 13 14 15 16 |
# File 'lib/faker/default/invoice.rb', line 9 def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0) warn_for_deprecated_arguments do |keywords| keywords << :from if legacy_from != NOT_GIVEN keywords << :to if legacy_to != NOT_GIVEN end Faker::Base.rand_in_range(from, to).round(2) end |
.creditor_reference(legacy_ref = NOT_GIVEN, ref: '') ⇒ Object
International bank slip reference en.wikipedia.org/wiki/Creditor_Reference ref is optional so that we can create unit tests
20 21 22 23 24 25 26 27 28 |
# File 'lib/faker/default/invoice.rb', line 20 def creditor_reference(legacy_ref = NOT_GIVEN, ref: '') warn_for_deprecated_arguments do |keywords| keywords << :ref if legacy_ref != NOT_GIVEN end ref = reference if ref.empty? 'RF' + iban_checksum('RF', ref) + ref end |
.reference(legacy_ref = NOT_GIVEN, ref: '') ⇒ Object
Payment references have some rules in certain countries ref is optional so that we can create unit tests
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/faker/default/invoice.rb', line 32 def reference(legacy_ref = NOT_GIVEN, ref: '') warn_for_deprecated_arguments do |keywords| keywords << :ref if legacy_ref != NOT_GIVEN end pattern = fetch('invoice.reference.pattern') ref = Base.regexify(/#{pattern}/) if ref.empty? # If reference contains reserved '#' characters we need to calculate check_digits as well check_digit_match = ref.match(/#+/) if check_digit_match # Get the method for selected language check_digit_method = fetch('invoice.reference.check_digit_method') # Calculate the check digit with matching method name # Trim all '#' from the reference before calculating that check_digit = send(check_digit_method, ref.tr('#', '')) # Make sure that our check digit is as long as all of the '###' we found check_digit = check_digit.to_s.rjust(check_digit_match[0].length, '0') # Replace all of the ref = ref.sub(check_digit_match[0], check_digit) end ref end |