Class: Camt::File

Inherits:
Object
  • Object
show all
Defined in:
lib/camt/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, options = {}) ⇒ File

Returns a new instance of File.



12
13
14
15
16
17
18
19
20
21
# File 'lib/camt/file.rb', line 12

def initialize(doc, options = {})
  self.code = options[:code] || 'CAMT'
  self.country_code = options[:country_code] || Camt.config.default_country_code || raise(ArgumentError.new("No country_code given and no default_country_code configured."))
  self.name = options[:name] || 'Generic CAMT Format'

  self.doc = doc
  self.ns = doc.namespaces['xmlns']

  check_version if valid?
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/camt/file.rb', line 3

def code
  @code
end

#country_codeObject

Returns the value of attribute country_code.



3
4
5
# File 'lib/camt/file.rb', line 3

def country_code
  @country_code
end

#docObject

Returns the value of attribute doc.



4
5
6
# File 'lib/camt/file.rb', line 4

def doc
  @doc
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/camt/file.rb', line 3

def name
  @name
end

#nsObject

Returns the value of attribute ns.



4
5
6
# File 'lib/camt/file.rb', line 4

def ns
  @ns
end

Class Method Details

.parse(file) ⇒ Object



8
9
10
# File 'lib/camt/file.rb', line 8

def self.parse file
  Camt::File.new(Nokogiri::XML(::File.read(file)))
end

Instance Method Details

#check_versionObject



27
28
29
30
31
32
# File 'lib/camt/file.rb', line 27

def check_version
  # Sanity check the document's namespace
  raise 'This does not seem to be a CAMT format bank statement' unless ns.start_with?('urn:iso:std:iso:20022:tech:xsd:camt.')
  raise 'Only CAMT.053 is supported at the moment.' unless ns.start_with?('urn:iso:std:iso:20022:tech:xsd:camt.053.')
  return true
end

#messagesObject



34
35
36
# File 'lib/camt/file.rb', line 34

def messages
  @messages ||= Parser.new.parse self
end

#statementsObject



38
39
40
# File 'lib/camt/file.rb', line 38

def statements
  @statements ||= messages.map(&:statements).flatten
end

#to_sObject



47
48
49
# File 'lib/camt/file.rb', line 47

def to_s
  "#{name}: #{messages.map{|message| message.group_header.message_id }.join(', ')}"
end

#transactionsObject



42
43
44
# File 'lib/camt/file.rb', line 42

def transactions
  @transactions ||= statements.map(&:transactions).flatten
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/camt/file.rb', line 23

def valid?
  doc.errors.empty?
end