Class: Twinfield::Customer::Bank

Inherits:
Object
  • Object
show all
Defined in:
lib/twinfield/customer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ascription: nil, accountnumber: nil, address: nil, bankname: nil, biccode: nil, city: nil, country: nil, iban: nil, natbiccode: nil, postcode: nil, state: nil, id: nil, default: nil) ⇒ Bank

Returns a new instance of Bank.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/twinfield/customer.rb', line 70

def initialize(ascription: nil, accountnumber: nil, address: nil, bankname: nil, biccode: nil, city: nil, country: nil, iban: nil, natbiccode: nil, postcode: nil, state: nil, id: nil, default: nil)
  @ascription = ascription
  @accountnumber = accountnumber
  @address = (address.is_a?(Hash) && address != {}) ? Address.new(**address) : address
  @bankname = bankname
  @biccode = biccode
  @city = city
  @country = country
  @iban = iban
  @natbiccode = natbiccode
  @postcode = postcode
  @state = state
  @default = ["true", true, 1, "1"].include?(default)
  @id = id
end

Instance Attribute Details

#accountnumberObject

Returns the value of attribute accountnumber.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def accountnumber
  @accountnumber
end

#addressObject

Returns the value of attribute address.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def address
  @address
end

#ascriptionObject

Returns the value of attribute ascription.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def ascription
  @ascription
end

#banknameObject

Returns the value of attribute bankname.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def bankname
  @bankname
end

#biccodeObject

Returns the value of attribute biccode.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def biccode
  @biccode
end

#cityObject

Returns the value of attribute city.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def city
  @city
end

#countryObject

Returns the value of attribute country.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def country
  @country
end

#defaultObject

Returns the value of attribute default.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def default
  @default
end

#ibanObject

Returns the value of attribute iban.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def iban
  @iban
end

#idObject

Returns the value of attribute id.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def id
  @id
end

#natbiccodeObject

Returns the value of attribute natbiccode.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def natbiccode
  @natbiccode
end

#postcodeObject

Returns the value of attribute postcode.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def postcode
  @postcode
end

#stateObject

Returns the value of attribute state.



68
69
70
# File 'lib/twinfield/customer.rb', line 68

def state
  @state
end

Class Method Details

.from_xml(nokogiri_xml) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/twinfield/customer.rb', line 126

def self.from_xml(nokogiri_xml)
  obj = new(id: nokogiri_xml.attributes["id"].text, default: nokogiri_xml.attributes["default"].text)
  obj.ascription = nokogiri_xml.css("ascription").text
  obj.accountnumber = nokogiri_xml.css("accountnumber").text
  obj.address = Address.from_xml(nokogiri_xml.css("address")[0]) if nokogiri_xml.css("address")[0] && nokogiri_xml.css("address")[0].children.count > 0
  obj.bankname = nokogiri_xml.css("bankname").text
  obj.biccode = nokogiri_xml.css("biccode").text
  obj.city = nokogiri_xml.css("city").text
  obj.country = nokogiri_xml.css("country").text
  obj.iban = nokogiri_xml.css("iban").text
  obj.natbiccode = nokogiri_xml.css("natbiccode").text
  obj.postcode = nokogiri_xml.css("postcode").text
  obj.state = nokogiri_xml.css("state").text
  obj
end

Instance Method Details

#to_hObject Also known as: to_hash



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/twinfield/customer.rb', line 86

def to_h
  {
    address: address.to_h,
    ascription: ascription,
    accountnumber: accountnumber,
    bankname: bankname,
    biccode: biccode,
    city: city,
    country: country,
    iban: iban,
    natbiccode: natbiccode,
    postcode: postcode,
    state: state,
    id: id,
    default: default
  }
end

#to_xmlObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/twinfield/customer.rb', line 105

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    attributes = {default: default}
    attributes[:id] = id if id

    xml.bank(attributes) do
      xml.ascription ascription
      xml.accountnumber accountnumber
      xml.address address
      xml.bankname bankname
      xml.biccode biccode
      xml.city city
      xml.country country
      xml.iban iban
      xml.natbiccode natbiccode
      xml.postcode postcode
      xml.state state
    end
  end.doc.root.to_xml
end