Class: Bankserv::OutputDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/bankserv/transmission/output_document.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Document

#input?, #mark_processed!, #output?, #records, #reply?, #set_with_dept_code, #set_with_generation_number, #sets, #to_hash

Class Method Details

.document_typeObject



10
11
12
# File 'lib/bankserv/transmission/output_document.rb', line 10

def self.document_type
  'output'
end

.for_user_ref(user_ref) ⇒ Object



38
39
40
# File 'lib/bankserv/transmission/output_document.rb', line 38

def self.for_user_ref(user_ref)
  where(type: 'output', user_ref: user_ref).first
end

.store(string) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bankserv/transmission/output_document.rb', line 14

def self.store(string)
  options = Absa::H2h::Transmission::Document.hash_from_s(string, 'output')
  
  raise "Expected a document set" unless options[:type] == "document"
  
  document = Bankserv::OutputDocument.new(
    type: 'output',
    client_code: options[:data][0][:data][:client_code]
  )
  
  document.set = Bankserv::Set.from_hash(options)
  document.set.document = document # whaaaaaa?
  document.save!
  document
end

Instance Method Details

#process!Object



30
31
32
33
34
35
36
# File 'lib/bankserv/transmission/output_document.rb', line 30

def process!
  raise "Document already processed" if processed?
  
  self.set.process
  self.processed = true
  self.save
end

#set_user_ref!Object



5
6
7
8
# File 'lib/bankserv/transmission/output_document.rb', line 5

def set_user_ref!
  self.user_ref ||= self.set.header.data[:th_for_use_of_ld_user]
  self.save!
end