Class: LitleOnline::EnhancedData

Inherits:
Object
  • Object
show all
Includes:
XML::Mapping
Defined in:
lib/XMLFields.rb

Class Method Summary collapse

Class Method Details

.from_hash(hash, name = 'enhancedData') ⇒ Object



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/XMLFields.rb', line 564

def self.from_hash(hash, name='enhancedData')
  base = hash[name]
  if(base)
    this = EnhancedData.new
    this.customerReference = base['customerReference']
    this.salesTax = base['salesTax']
    this.deliveryType = base['deliveryType']
    this.taxExempt = base['taxExempt']
    this.discountAmount = base['discountAmount']
    this.shippingAmount = base['shippingAmount']
    this.dutyAmount = base['dutyAmount']
    this.shipFromPostalCode = base['shipFromPostalCode']
    this.destinationPostalCode = base['destinationPostalCode']
    this.destinationCountryCode = base['destinationCountryCode']
    this.invoiceReferenceNumber = base['invoiceReferenceNumber']
    this.orderDate = base['orderDate']
    if(base['detailTax'])
      base['detailTax'].each_index {|index| this.detailTax << DetailTax.from_hash(base,index)}
    end
    if(base['lineItemData'])
      base['lineItemData'].each_index {|index| this.lineItemData << LineItemData.from_hash(base,index)}
    end
    SchemaValidation.validate_length(this.customerReference, false, 1, 17, name, 'customerReference')
    SchemaValidation.validate_size(this.salesTax, false, -999999999999, 999999999999, name, 'salesTax')
    SchemaValidation.validate_enum(this.deliveryType, false, ['CNC','DIG','PHY','SVC','TBD'], name, 'deliveryType')
    SchemaValidation.validate_boolean(this.taxExempt, false, name, 'taxExempt')
    SchemaValidation.validate_size(this.discountAmount, false, -999999999999, 999999999999, name, 'discountAmount')
    SchemaValidation.validate_size(this.shippingAmount, false, -999999999999, 999999999999, name, 'shippingAmount')
    SchemaValidation.validate_size(this.dutyAmount, false, -999999999999, 999999999999, name, 'dutyAmount')
    SchemaValidation.validate_length(this.shipFromPostalCode, false, 1, 20, name, 'shipFromPostalCode')
    SchemaValidation.validate_length(this.destinationPostalCode, false, 1, 20, name, 'destinationPostalCode')
    SchemaValidation.validate_country(this.destinationCountryCode, name, 'destinationCountryCode')
    SchemaValidation.validate_length(this.invoiceReferenceNumber, false, 1, 15, name, 'invoiceReferenceNumber')
    SchemaValidation.validate_date(this.orderDate, false, name, 'orderDate')
    this
  else
    nil
  end
end