Class: SupplierPayments::PaymentFile::AbstractRecord
- Inherits:
-
Object
- Object
- SupplierPayments::PaymentFile::AbstractRecord
- Defined in:
- lib/supplier_payments/payment_file/records.rb
Direct Known Subclasses
AccountNumberRecord, AddressRecord, CreditInvoiceWithMonitoringRecord, DeductionRecord, FixedInformationRecord, HeaderRecord, InformationRecord, NameRecord, OpeningRecord, PaymentRecord, PlusGiroInformationRecord, PlusGiroPaymentRecord, TotalAmountRecord
Constant Summary collapse
- LayoutError =
Class.new(Exception)
- FormatError =
Class.new(Exception)
Class Attribute Summary collapse
-
.layout ⇒ Object
readonly
Returns the value of attribute layout.
-
.transaction_code ⇒ Object
Returns the value of attribute transaction_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ AbstractRecord
constructor
A new instance of AbstractRecord.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #transaction_code ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ AbstractRecord
Returns a new instance of AbstractRecord.
52 53 54 55 56 |
# File 'lib/supplier_payments/payment_file/records.rb', line 52 def initialize(attrs = {}) attrs.each do |key, value| self.send("#{key}=", value) end end |
Class Attribute Details
.layout ⇒ Object
Returns the value of attribute layout.
9 10 11 |
# File 'lib/supplier_payments/payment_file/records.rb', line 9 def layout @layout end |
.transaction_code ⇒ Object
Returns the value of attribute transaction_code.
8 9 10 |
# File 'lib/supplier_payments/payment_file/records.rb', line 8 def transaction_code @transaction_code end |
Class Method Details
.parse(line) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/supplier_payments/payment_file/records.rb', line 37 def self.parse(line) io = StringIO.new(line) record = new layout.each do |field, length, format, *opts| if field[-1] == "!" io.seek(length, IO::SEEK_CUR) else record.send("#{field}=", io.read(length)) end end record end |
Instance Method Details
#inspect ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/supplier_payments/payment_file/records.rb', line 64 def inspect str = self.class.layout.map { |field, length, format, *opts| next if field[-1] == "!" ":#{field} => #{send(field).inspect}" }.compact.join(", ") "<#{self.class.name}(#{transaction_code}) #{str}>" end |
#to_s ⇒ Object
58 59 60 61 62 |
# File 'lib/supplier_payments/payment_file/records.rb', line 58 def to_s self.class.layout.map { |field, length, format, *opts| format_field(field, length, format, *opts) }.join end |
#transaction_code ⇒ Object
73 74 75 |
# File 'lib/supplier_payments/payment_file/records.rb', line 73 def transaction_code self.class.transaction_code end |