Class: SwissQRBill::QRBill

Inherits:
Object
  • Object
show all
Defined in:
lib/swiss_qr_bill/qr_bill.rb

Overview

rubocop:disable Style/DataInheritance

Defined Under Namespace

Classes: Address

Constant Summary collapse

Header =
Data.define(:qr_type, :version, :coding_type)
CreditorInformation =
Data.define(:iban)
PaymentReference =
Data.define(:type, :reference, :additional_information)
Trailer =
Data.define(:trailer)
PaymentAmountInformation =
Data.define(:amount, :currency) do
  def initialize(amount:, currency:)
    super(amount: amount.to_f, currency:)
  end
end
CombinedAddress =
Data.define(:type, :name, :line1, :line2, :country) do
  def street = line1
  def building_number = line1
  def postal_code = line2
  def town = line2
end
StructuredAddress =
Data.define(:type, :name, :street, :building_number, :postal_code, :town, :country) do
  def line1 = "#{street} #{building_number}"
  def line2 = "#{postal_code} #{town}"
end
AdditionalInformation =
Data.define(:billing_information, :av1, :av2) do
  def initialize(billing_information: nil, av1: nil, av2: nil)
    super
  end
end
REGIONS =
{
  00..02 => [:header, Header],
  03..03 => [:creditor_information, CreditorInformation],
  04..10 => [:creditor, Address],
  11..17 => [:ulimate_creditor, Address],
  18..19 => [:payment_amount_information, PaymentAmountInformation],
  20..26 => [:debtor, Address],
  27..29 => [:payment_reference, PaymentReference],
  30..30 => [:trailer, Trailer],
  31..33 => [:additional_information, AdditionalInformation]
}.freeze

Instance Method Summary collapse

Instance Method Details

#to_raw_dataObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/swiss_qr_bill/qr_bill.rb', line 67

def to_raw_data
  [
    header,
    creditor_information,
    creditor,
    ulimate_creditor,
    payment_amount_information,
    debtor,
    payment_reference,
    trailer,
    additional_information
  ].flat_map(&:deconstruct).map(&:to_s)
end

#to_sObject



81
82
83
# File 'lib/swiss_qr_bill/qr_bill.rb', line 81

def to_s
  to_raw_data.join("\n")
end