Class: Codabel::Model::Account
- Inherits:
-
Codabel::Model
- Object
- OpenStruct
- Codabel::Model
- Codabel::Model::Account
- Defined in:
- lib/codabel/model/account.rb
Constant Summary collapse
- BELGIAN_BBAN =
:belgian_bban
- FOREIGN_BBAN =
:foreign_bban
- BELGIAN_IBAN =
:belgian_iban
- FOREIGN_IBAN =
:foreign_iban
Class Method Summary collapse
Instance Method Summary collapse
- #check!(attributes) ⇒ Object
- #currency ⇒ Object
- #infer_structure ⇒ Object
-
#initialize(attributes = {}) ⇒ Account
constructor
A new instance of Account.
- #number ⇒ Object
- #structure ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Account
Returns a new instance of Account.
9 10 11 |
# File 'lib/codabel/model/account.rb', line 9 def initialize(attributes = {}) super(check!(attributes)) end |
Class Method Details
.dress(value) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/codabel/model/account.rb', line 24 def self.dress(value) case value when Account then value when String then new(number: value) when Hash then new(value) else raise ArgumentError, "Unable to dress `#{value}` as an Account" end end |
Instance Method Details
#check!(attributes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/codabel/model/account.rb', line 13 def check!(attributes) attributes = attributes.dup if (c = attributes[:currency]) c = attributes[:currency] = c.strip raise ValidationError, "Wrong currency #{c}" unless c =~ /^[A-Z]{3}$/ end attributes end |
#currency ⇒ Object
34 35 36 |
# File 'lib/codabel/model/account.rb', line 34 def currency @currency ||= (super || 'EUR').to_s.gsub(/\s/, '') end |
#infer_structure ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/codabel/model/account.rb', line 46 def infer_structure case number.to_s.strip when /^BE\d{14}$/ BELGIAN_IBAN when /^[A-Z]{2}\d{2}\d{12,30}/ FOREIGN_IBAN when /^\d{12}$/ BELGIAN_BBAN else FOREIGN_BBAN end end |
#number ⇒ Object
38 39 40 |
# File 'lib/codabel/model/account.rb', line 38 def number @number ||= super.to_s.gsub(/\s/, '') end |
#structure ⇒ Object
42 43 44 |
# File 'lib/codabel/model/account.rb', line 42 def structure @structure ||= super || infer_structure end |