Class: Dhl::Intraship::DhlExpressService

Inherits:
Service
  • Object
show all
Defined in:
lib/dhl-intraship/service/dhl_express_service.rb

Constant Summary collapse

DELIVERY_ON_TIME =

Bundles following services for domestic time-definite products offered by DHL Express. One of the services must be chosen, if this service bundle is invoked

'DeliveryOnTime'
DELIVERY_EARLY =
'DeliveryEarly'
EXPRESS0900 =
'Express0900'
EXPRESS1000 =
'Express1000'
EXPRESS1200 =
'Express1200'
DELIVERY_AFTERNOON =
'DeliveryAfternoon'
DELIVERY_EVENING =
'DeliveryEvening'
EXPRESS_SATURDAY =
'ExpressSaturday'
EXPRESS_SUNDAY =
'Expresssunday'
VALID_EXPRESS_SERVICES =
[DELIVERY_ON_TIME, DELIVERY_EARLY, EXPRESS0900, EXPRESS1000, EXPRESS1200,
DELIVERY_AFTERNOON, DELIVERY_EVENING, EXPRESS_SATURDAY, EXPRESS_SUNDAY]

Instance Method Summary collapse

Constructor Details

#initialize(service, time = nil) ⇒ DhlExpressService

Returns a new instance of DhlExpressService.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dhl-intraship/service/dhl_express_service.rb', line 23

def initialize(service, time = nil)
  @service, @time = service, time
  unless VALID_EXPRESS_SERVICES.include?(@service)
    raise "No valid express service #{@service}"
  end

  if @service == DELIVERY_ON_TIME
    raise "Time is missing while DeliveryOnTime is specified." if time.blank?
    raise "Invalid time format (use hh::mm)." if time !~ /^\d\d:\d\d$/
  end
end

Instance Method Details

#append_to_xml(xml) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/dhl-intraship/service/dhl_express_service.rb', line 35

def append_to_xml(xml)
  xml.Service do |xml|
    xml.ServiceGroupDateTimeOption do |xml|
      xml.tag! @service, @time || 'True'
    end
  end
end