Class: Sepa::Base
- Inherits:
-
Object
- Object
- Sepa::Base
- Includes:
- Aduki::Initializer
- Defined in:
- lib/sepa/base.rb
Direct Known Subclasses
PaymentsInitiation::AccountIdentificationChoice, PaymentsInitiation::AccountSchemeNameChoice, PaymentsInitiation::Authorisation, PaymentsInitiation::BranchAndFinancialInstitutionIdentification, PaymentsInitiation::CashAccount, PaymentsInitiation::CashAccountTypeChoice, PaymentsInitiation::CategoryPurposeChoice, PaymentsInitiation::ContactDetails, PaymentsInitiation::FinancialInstitutionIdentification, PaymentsInitiation::GenericAccountIdentification, PaymentsInitiation::GenericOrganisationIdentification1, PaymentsInitiation::GenericPersonIdentification1, PaymentsInitiation::LocalInstrumentChoice, PaymentsInitiation::OrganisationIdentification, PaymentsInitiation::OrganisationIdentificationSchemeName1Choice, PaymentsInitiation::Pain00800104::CustomerDirectDebitInitiation, PaymentsInitiation::Pain00800104::DirectDebitTransaction, PaymentsInitiation::Pain00800104::DirectDebitTransactionInformation, PaymentsInitiation::Pain00800104::GroupHeader, PaymentsInitiation::Pain00800104::MandateRelatedInformation, PaymentsInitiation::Pain00800104::PaymentIdentification, PaymentsInitiation::Pain00800104::PaymentInformation, PaymentsInitiation::Pain00800104::PaymentTypeInformation, PaymentsInitiation::Pain00800104::PurposeChoice, PaymentsInitiation::Pain00800104::RegulatoryAuthority, PaymentsInitiation::Pain00800104::RegulatoryReporting, PaymentsInitiation::Pain00800104::ServiceLevelChoice, PaymentsInitiation::Pain00800104::StructuredRegulatoryReporting, PaymentsInitiation::Pain00800104::TaxAuthorisation, PaymentsInitiation::Pain00800104::TaxInformation, PaymentsInitiation::Pain00800104::TaxParty, PaymentsInitiation::PartyChoiceIdentification, PaymentsInitiation::PartyIdentification, PaymentsInitiation::PersonIdentificationSchemeName1Choice, PaymentsInitiation::PostalAddress, PaymentsInitiation::PrivateIdentification
Constant Summary collapse
- @@attribute_defs =
Hash.new { |h,k| h[k] = [] }
Class Method Summary collapse
- .array_attribute(name, tag, member_type = nil, options = { }) ⇒ Object
- .attribute(name, tag, type = :string, member_type = nil, options = { }) ⇒ Object
- .attribute_defs ⇒ Object
- .attribute_defs=(arg) ⇒ Object
- .code_or_proprietary ⇒ Object
- .definition(txt) ⇒ Object
- .typed_attribute(name, tag, type, options) ⇒ Object
Instance Method Summary collapse
- #build_xml_attributes(names) ⇒ Object
- #empty? ⇒ Boolean
- #normalize(str) ⇒ Object
- #to_xml(builder) ⇒ Object
Class Method Details
.array_attribute(name, tag, member_type = nil, options = { }) ⇒ Object
95 96 97 98 99 |
# File 'lib/sepa/base.rb', line 95 def self.array_attribute name, tag, member_type=nil, ={ } attribute_defs << [name, { :tag => tag, :type => :[], :member_type => member_type, :options => }] attr_accessor name aduki(name => member_type) if member_type end |
.attribute(name, tag, type = :string, member_type = nil, options = { }) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sepa/base.rb', line 78 def self.attribute name, tag, type=:string, member_type=nil, ={ } if type == :[] array_attribute name, tag, member_type, elsif type.is_a?(Class) && type != Time && type != Date typed_attribute name, tag, type, else attr_accessor name attribute_defs << [name, { :tag => tag, :type => type, :options => }] end end |
.attribute_defs ⇒ Object
62 63 64 |
# File 'lib/sepa/base.rb', line 62 def self.attribute_defs @@attribute_defs[self] end |
.attribute_defs=(arg) ⇒ Object
66 67 68 |
# File 'lib/sepa/base.rb', line 66 def self.attribute_defs= arg @@attribute_defs[self]= arg end |
.code_or_proprietary ⇒ Object
73 74 75 76 |
# File 'lib/sepa/base.rb', line 73 def self.code_or_proprietary attribute :code , "Cd" attribute :proprietary, "Prtry" end |
.definition(txt) ⇒ Object
70 71 |
# File 'lib/sepa/base.rb', line 70 def self.definition txt end |
.typed_attribute(name, tag, type, options) ⇒ Object
89 90 91 92 93 |
# File 'lib/sepa/base.rb', line 89 def self.typed_attribute name, tag, type, attribute_defs << [name, { :tag => tag, :type => type, :options => }] attr_accessor name aduki name => type end |
Instance Method Details
#build_xml_attributes(names) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/sepa/base.rb', line 8 def build_xml_attributes names result = { } (names || { }).each { |k,v| result[k] = self.send v } result end |
#empty? ⇒ Boolean
16 17 18 |
# File 'lib/sepa/base.rb', line 16 def empty? false end |
#normalize(str) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sepa/base.rb', line 20 def normalize str return str if str.is_a? Fixnum return ("%.2f" % str) if str.is_a? Float replacements = { 'à' => 'a', 'é' => 'e', 'è' => 'e', 'û' => 'u', 'î' => 'i', 'ô' => 'o', 'ü' => 'u', 'ï' => 'i', 'ö' => 'o', 'ÿ' => 'y', 'ç' => 'c', 'Ç' => 'C', 'É' => 'E', 'È' => 'E', 'á' => 'a', 'À' => 'A', 'Á' => 'A', 'Ü' => 'U', 'Ï' => 'I', 'Ö' => 'O', 'ß' => 'ss' } str = replacements.to_a. inject(str) { |s, kv| s.gsub(kv[0], kv[1]) }. gsub(/[^a-zA-Z0-9_@ \.,()'+\/\?-]/, '') end |
#to_xml(builder) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sepa/base.rb', line 34 def to_xml builder self.class.attribute_defs.each do |name, | item = self.send(name) = [:options] || { } attributes = build_xml_attributes [:attributes] next if item == nil || (item.is_a?(Sepa::Base) && item.empty?) if [:type] == :string builder.__send__([:tag], normalize(item), attributes) elsif [:type] == :[] if [:member_type] == nil item.each { |obj| builder.__send__([:tag], normalize(obj), attributes) } else item.each do |obj| builder.__send__([:tag], attributes) { obj.to_xml builder } end end elsif [:type] == Time v = item.is_a?(String) ? item : item.strftime("%Y-%m-%dT%H:%M:%SZ") builder.__send__([:tag], v, attributes) elsif [:type] == Date v = item.is_a?(String) ? item : item.strftime("%Y-%m-%d") builder.__send__([:tag], v, attributes) elsif [:type].is_a? Class builder.__send__([:tag], attributes) { item.to_xml builder } end end end |