Class: Google4R::Checkout::ShippingMethod
- Inherits:
-
DeliveryMethod
- Object
- DeliveryMethod
- Google4R::Checkout::ShippingMethod
- Defined in:
- lib/google4r/checkout/shared.rb
Overview
Abstract class for shipping methods. Do not use this class directly but only one of its subclasses.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#shipping_restrictions_allowed_areas ⇒ Object
readonly
An Array of allowed areas for shipping-restrictions of this shipping instance.
-
#shipping_restrictions_excluded_areas ⇒ Object
readonly
An Array of excluded areas for shipping-restrictions of this shipping instance.
Attributes inherited from DeliveryMethod
Instance Method Summary collapse
-
#create_allowed_area(clazz, &block) ⇒ Object
(also: #create_shipping_restrictions_allowed_area)
Creates a new Area, adds it to the internal list of allowed areas for shipping restrictions.
-
#create_area(type, areas, clazz) {|area| ... } ⇒ Object
This method create a new instance of subclass of Area and put it in the array determined by the two symbols provided.
-
#create_excluded_area(clazz, &block) ⇒ Object
(also: #create_shipping_restrictions_excluded_area)
Creates a new Area, adds it to the internal list of excluded areas for shipping restrictions.
-
#initialize ⇒ ShippingMethod
constructor
A new instance of ShippingMethod.
Constructor Details
#initialize ⇒ ShippingMethod
Returns a new instance of ShippingMethod.
779 780 781 782 |
# File 'lib/google4r/checkout/shared.rb', line 779 def initialize @shipping_restrictions_allowed_areas = Array.new @shipping_restrictions_excluded_areas = Array.new end |
Instance Attribute Details
#shipping_restrictions_allowed_areas ⇒ Object (readonly)
An Array of allowed areas for shipping-restrictions of this shipping instance. Use #create_allowed_area to add to this area but do not change it directly.
773 774 775 |
# File 'lib/google4r/checkout/shared.rb', line 773 def shipping_restrictions_allowed_areas @shipping_restrictions_allowed_areas end |
#shipping_restrictions_excluded_areas ⇒ Object (readonly)
An Array of excluded areas for shipping-restrictions of this shipping instance. Use #create_excluded_area to add to this area but do not change it directly.
777 778 779 |
# File 'lib/google4r/checkout/shared.rb', line 777 def shipping_restrictions_excluded_areas @shipping_restrictions_excluded_areas end |
Instance Method Details
#create_allowed_area(clazz, &block) ⇒ Object Also known as: create_shipping_restrictions_allowed_area
Creates a new Area, adds it to the internal list of allowed areas for shipping restrictions. If you passed a block (preferred) then the block is called with the Area as the only parameter.
The area to be created depends on the given parameter clazz. It can be one of { PostalArea, UsCountryArea, UsStateArea, UsZipArea, WorldArea }.
Raises a RuntimeError if the parameter clazz is invalid.
Example
method = FlatRateShipping.new
method.create_allowed_area(UsCountryArea) do |area|
area.area = UsCountryArea::ALL
end
834 835 836 |
# File 'lib/google4r/checkout/shared.rb', line 834 def create_allowed_area(clazz, &block) return create_area(:shipping_restrictions, :allowed_areas, clazz, &block) end |
#create_area(type, areas, clazz) {|area| ... } ⇒ Object
This method create a new instance of subclass of Area and put it in the array determined by the two symbols provided. The valid symbols for the first two parameters are:
type : :shipping_restrictions, :address_filters areas : :allowed_areas, :excluded_areas
The third parameter clazz is used to specify the type of Area you want to create. It can be one of { PostalArea, UsCountryArea, UsStateArea, UsZipArea, WorldArea }.
Raises a RuntimeError if the parameter clazz is invalid.
If you passed a block (preferred) then the block is called with the Area as the only parameter.
Example
method = MerchantCalculatedShipping.new
method.create_area(:shipping_restrictions, :allowed_areas, UsCountryArea) do |area|
area.area = UsCountryArea::ALL
end
806 807 808 809 810 811 812 813 814 815 816 817 |
# File 'lib/google4r/checkout/shared.rb', line 806 def create_area(type, areas, clazz, &block) areas_array_name = "@#{type.to_s + '_' + areas.to_s}" areas = instance_variable_get(areas_array_name) raise "Undefined instance variable: #{areas_array_name}" unless areas.nil? == false raise "Invalid Area class: #{clazz}!" unless [ PostalArea, UsCountryArea, UsStateArea, UsZipArea, WorldArea ].include?(clazz) area = clazz.new areas << area yield(area) if block_given? return area end |
#create_excluded_area(clazz, &block) ⇒ Object Also known as: create_shipping_restrictions_excluded_area
Creates a new Area, adds it to the internal list of excluded areas for shipping restrictions. If you passed a block (preferred) then the block is called with the Area as the only parameter. The created area is returned in any case.
The area to be created depends on the given parameter clazz. It can be one of { PostalArea, UsCountryArea, UsStateArea, UsZipArea, WorldArea }.
Raises a RuntimeError if the parameter clazz is invalid.
Example
method = FlatRateShipping.new
method.create_excluded_area(UsCountryArea) do |area|
area.area = UsCountryArea::ALL
end
853 854 855 |
# File 'lib/google4r/checkout/shared.rb', line 853 def create_excluded_area(clazz, &block) return create_area(:shipping_restrictions, :excluded_areas, clazz, &block) end |