Class: Google4R::Checkout::CarrierCalculatedShipping

Inherits:
Object
  • Object
show all
Defined in:
lib/google4r/checkout/shared.rb

Overview

A class that represents the "merchant-calculated" shipping method

Defined Under Namespace

Classes: CarrierCalculatedShippingOption, ShippingPackage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCarrierCalculatedShipping



930
931
932
933
# File 'lib/google4r/checkout/shared.rb', line 930

def initialize()
  @carrier_calculated_shipping_options = Array.new
  @shipping_packages = Array.new
end

Instance Attribute Details

#carrier_calculated_shipping_optionsObject (readonly)

This encapsulates information about all of the shipping methods for which Google Checkout should obtain shipping costs.



923
924
925
# File 'lib/google4r/checkout/shared.rb', line 923

def carrier_calculated_shipping_options
  @carrier_calculated_shipping_options
end

#shipping_packagesObject (readonly)

This encapsulates information about all of the packages that will be shipped to the buyer. At this time, merchants may only specify one package per order.



928
929
930
# File 'lib/google4r/checkout/shared.rb', line 928

def shipping_packages
  @shipping_packages
end

Instance Method Details

#create_carrier_calculated_shipping_option {|option| ... } ⇒ Object

Yields:

  • (option)


935
936
937
938
939
940
941
942
943
# File 'lib/google4r/checkout/shared.rb', line 935

def create_carrier_calculated_shipping_option(&block)
  option = CarrierCalculatedShippingOption.new(self)
  @carrier_calculated_shipping_options << option
  
  # Pass the newly generated rule to the given block to set its attributes.
  yield(option) if block_given?
  
  return option
end

#create_from_element(element) ⇒ Object

Creates a new CarrierCalculatedShipping from the given REXML::Element instance. For testing only.



958
959
960
961
962
963
964
965
966
# File 'lib/google4r/checkout/shared.rb', line 958

def create_from_element(element)
  result = CarrierCalculatedShipping.new
  element.elements.each('carrier-calculated-shipping-options/carrier-calculated-shipping-option') do |shipping_option_element|
    result.carrier_calculated_shipping_options << CarrierCalculatedShippingOption.create_from_element(self, shipping_option_element)
  end
  element.elements.each('shipping-packages/shipping-package') do |shipping_package_element|
    result.shipping_packages << ShippingPackage.create_from_element(self, shipping_package_element)
  end
end

#create_shipping_package {|package| ... } ⇒ Object

Yields:

  • (package)


945
946
947
948
949
950
951
952
953
# File 'lib/google4r/checkout/shared.rb', line 945

def create_shipping_package(&block)
  package = ShippingPackage.new(self)
  @shipping_packages << package
  
  # Pass the newly generated rule to the given block to set its attributes.
  yield(package) if block_given?
  
  return package
end