Class: Camt::File
- Inherits:
-
Object
- Object
- Camt::File
- Defined in:
- lib/camt/file.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ns ⇒ Object
Returns the value of attribute ns.
Class Method Summary collapse
Instance Method Summary collapse
- #check_version ⇒ Object
-
#initialize(doc, options = {}) ⇒ File
constructor
A new instance of File.
- #messages ⇒ Object
- #statements ⇒ Object
- #to_s ⇒ Object
- #transactions ⇒ Object
- #valid? ⇒ Boolean
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, = {}) self.code = [:code] || 'CAMT' self.country_code = [:country_code] || Camt.config.default_country_code || raise(ArgumentError.new("No country_code given and no default_country_code configured.")) self.name = [:name] || 'Generic CAMT Format' self.doc = doc self.ns = doc.namespaces['xmlns'] check_version if valid? end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/camt/file.rb', line 3 def code @code end |
#country_code ⇒ Object
Returns the value of attribute country_code.
3 4 5 |
# File 'lib/camt/file.rb', line 3 def country_code @country_code end |
#doc ⇒ Object
Returns the value of attribute doc.
4 5 6 |
# File 'lib/camt/file.rb', line 4 def doc @doc end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/camt/file.rb', line 3 def name @name end |
#ns ⇒ Object
Returns the value of attribute ns.
4 5 6 |
# File 'lib/camt/file.rb', line 4 def ns @ns end |
Class Method Details
Instance Method Details
#check_version ⇒ Object
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 |
#messages ⇒ Object
34 35 36 |
# File 'lib/camt/file.rb', line 34 def @messages ||= Parser.new.parse self end |
#statements ⇒ Object
38 39 40 |
# File 'lib/camt/file.rb', line 38 def statements @statements ||= .map(&:statements).flatten end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/camt/file.rb', line 47 def to_s "#{name}: #{.map{|| .group_header. }.join(', ')}" end |
#transactions ⇒ Object
42 43 44 |
# File 'lib/camt/file.rb', line 42 def transactions @transactions ||= statements.map(&:transactions).flatten end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/camt/file.rb', line 23 def valid? doc.errors.empty? end |