Class: Faker::Invoice

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/invoice.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

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) ⇒ Integer

Produces a random amount between values with 2 decimals

Examples:

Faker::Finance.amount_between #=> 0
Faker::Finance.amount_between(0, 10) #=> 4.33

Parameters:

  • from (Integer) (defaults to: 0)

    Specifies lower limit.

  • to (Integer) (defaults to: 0)

    Specifies upper limit.

Returns:

  • (Integer)

Available since:

  • 1.9.0


20
21
22
23
24
25
26
27
# File 'lib/faker/default/invoice.rb', line 20

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: '') ⇒ String

Produces a random valid reference accoring to the International bank slip reference en.wikipedia.org/wiki/Creditor_Reference

Examples:

Faker::Invoice.creditor_reference #=> "RF34118592570724925498"

Parameters:

  • ref (String) (defaults to: '')

    Specifies reference base.

Returns:

  • (String)

Available since:

  • 1.9.0


39
40
41
42
43
44
45
46
47
# File 'lib/faker/default/invoice.rb', line 39

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: '') ⇒ String

Produces a random valid reference.

Examples:

Faker::Invoice.reference #=> "45656646957845"

Parameters:

  • ref (String) (defaults to: '')

    Specifies reference base.

Returns:

  • (String)

Available since:

  • 1.9.0


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/faker/default/invoice.rb', line 59

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