Class: Twinfield::Customer::Address

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

Constant Summary collapse

TYPES =
[:invoice, :postal, :contact]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, country: nil, ictcountrycode: nil, city: nil, postcode: nil, telephone: nil, telefax: nil, email: nil, contact: nil, field1: nil, field2: nil, field3: nil, field4: nil, field5: nil, field6: nil, id: nil, type: nil, default: nil) ⇒ Address

Returns a new instance of Address.



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/twinfield/customer.rb', line 332

def initialize(name:, country: nil, ictcountrycode: nil, city: nil, postcode: nil, telephone: nil, telefax: nil, email: nil, contact: nil, field1: nil, field2: nil, field3: nil, field4: nil, field5: nil, field6: nil, id: nil, type: nil, default: nil)
  @name = name
  @country = country
  @ictcountrycode = ictcountrycode
  @city = city
  @postcode = postcode
  @telephone = telephone
  @telefax = telefax
  @email = email
  @contact = contact
  @field1 = field1
  @field2 = field2
  @field3 = field3
  @field4 = field4
  @field5 = field5
  @field6 = field6
  @id = id
  @type = type
  @default = ["true", true, 1, "1"].include?(default)
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def city
  @city
end

#contactObject

Returns the value of attribute contact.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def contact
  @contact
end

#countryObject

Returns the value of attribute country.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def country
  @country
end

#defaultObject

Returns the value of attribute default.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def default
  @default
end

#emailObject

Returns the value of attribute email.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def email
  @email
end

#field1Object

Returns the value of attribute field1.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field1
  @field1
end

#field2Object

Returns the value of attribute field2.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field2
  @field2
end

#field3Object

Returns the value of attribute field3.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field3
  @field3
end

#field4Object

Returns the value of attribute field4.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field4
  @field4
end

#field5Object

Returns the value of attribute field5.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field5
  @field5
end

#field6Object

Returns the value of attribute field6.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def field6
  @field6
end

#ictcountrycodeObject

Returns the value of attribute ictcountrycode.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def ictcountrycode
  @ictcountrycode
end

#idObject

Returns the value of attribute id.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def id
  @id
end

#nameObject

Returns the value of attribute name.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def name
  @name
end

#postcodeObject

Returns the value of attribute postcode.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def postcode
  @postcode
end

#telefaxObject

Returns the value of attribute telefax.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def telefax
  @telefax
end

#telephoneObject

Returns the value of attribute telephone.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def telephone
  @telephone
end

#typeObject

Returns the value of attribute type.



330
331
332
# File 'lib/twinfield/customer.rb', line 330

def type
  @type
end

Class Method Details

.from_xml(nokogiri) ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/twinfield/customer.rb', line 403

def self.from_xml nokogiri
  obj = new(id: nokogiri.attributes["id"]&.text, name: nokogiri.css("name")&.text, default: nokogiri.attributes["default"]&.text)
  obj.country = nokogiri.css("country").text
  obj.type = nokogiri.attributes["type"]&.text
  obj.ictcountrycode = nokogiri.css("ictcountrycode")&.text
  obj.city = nokogiri.css("city")&.text
  obj.postcode = nokogiri.css("postcode")&.text
  obj.telephone = nokogiri.css("telephone")&.text
  obj.telefax = nokogiri.css("telefax")&.text
  obj.email = nokogiri.css("email")&.text
  obj.contact = nokogiri.css("contact")&.text
  obj.field1 = nokogiri.css("field1")&.text
  obj.field2 = nokogiri.css("field2")&.text
  obj.field3 = nokogiri.css("field3")&.text
  obj.field4 = nokogiri.css("field4")&.text
  obj.field5 = nokogiri.css("field5")&.text
  obj.field6 = nokogiri.css("field6")&.text
  obj
end

Instance Method Details

#to_hObject Also known as: to_hash



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/twinfield/customer.rb', line 353

def to_h
  {
    name: name,
    country: country,
    ictcountrycode: ictcountrycode,
    city: city,
    postcode: postcode,
    telephone: telephone,
    telefax: telefax,
    email: email,
    contact: contact,
    field1: field1,
    field2: field2,
    field3: field3,
    field4: field4,
    field5: field5,
    field6: field6,
    type: type,
    id: id,
    default: default
  }
end

#to_sObject



377
378
379
# File 'lib/twinfield/customer.rb', line 377

def to_s
  [name, field1, field2, [country, postcode, city].join(" ")].select { |a| !(a.nil? || a.empty?) }.join("\n")
end

#to_xmlObject



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/twinfield/customer.rb', line 381

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.address(id: @id, type: @type, default: @default) do
      xml.name name
      xml.country country
      xml.ictcountrycode ictcountrycode
      xml.city city
      xml.postcode postcode
      xml.telephone telephone
      xml.telefax telefax
      xml.email email
      xml.contact contact
      xml.field1 field1
      xml.field2 field2
      xml.field3 field3
      xml.field4 field4
      xml.field5 field5
      xml.field6 field6
    end
  end.doc.root.to_xml
end