Class: Faker::Invoice
Constant Summary
Constants inherited from Base
Base::Letters, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.amount_between(from = 0, to = 0) ⇒ Object
Generate random amount between values with 2 decimals.
-
.creditor_reference(ref = '') ⇒ Object
International bank slip reference en.wikipedia.org/wiki/Creditor_Reference ref is optional so that we can create unit tests.
-
.reference(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(from = 0, to = 0) ⇒ Object
Generate random amount between values with 2 decimals
9 10 11 |
# File 'lib/faker/default/invoice.rb', line 9 def amount_between(from = 0, to = 0) Faker::Base.rand_in_range(from, to).round(2) end |
.creditor_reference(ref = '') ⇒ Object
International bank slip reference en.wikipedia.org/wiki/Creditor_Reference ref is optional so that we can create unit tests
15 16 17 18 19 |
# File 'lib/faker/default/invoice.rb', line 15 def creditor_reference(ref = '') ref = reference if ref.empty? 'RF' + iban_checksum('RF', ref) + ref end |
.reference(ref = '') ⇒ Object
Payment references have some rules in certain countries ref is optional so that we can create unit tests
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/faker/default/invoice.rb', line 23 def reference(ref = '') 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 |