Class: Google4R::Checkout::FlatRateShipping

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

Overview

A class that represents the “flat_rate” shipping method.

Instance Attribute Summary collapse

Attributes inherited from ShippingMethod

#name, #price

Instance Method Summary collapse

Constructor Details

#initializeFlatRateShipping

Returns a new instance of FlatRateShipping.



443
444
445
446
# File 'lib/google4r/checkout/shared.rb', line 443

def initialize
  @allowed_areas = Array.new
  @excluded_areas = Array.new
end

Instance Attribute Details

#allowed_areasObject (readonly)

An Array of allowed areas for this flat_rate shipping instance. Use #create_allowed_area to add to this area but do not change it directly.



437
438
439
# File 'lib/google4r/checkout/shared.rb', line 437

def allowed_areas
  @allowed_areas
end

#excluded_areasObject (readonly)

An Array of excluded areas for this flat_rate shipping instance. Use #create_excluded_area to add to this area but do not change it directly.



441
442
443
# File 'lib/google4r/checkout/shared.rb', line 441

def excluded_areas
  @excluded_areas
end

Instance Method Details

#create_allowed_area(clazz) {|area| ... } ⇒ Object

Creates a new Area, adds it to the internal list of allowed areas for this shipping types. If you passed a block (preferred) then the block is called with the Area as the only parameter.c

The area to be created depends on the given parameter clazz. It can be one of { UsCountryArea, UsStateArea, UsZipArea }.

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

Yields:

  • (area)


463
464
465
466
467
468
469
470
471
472
# File 'lib/google4r/checkout/shared.rb', line 463

def create_allowed_area(clazz, &block)
  raise "Invalid Area class: #{clazz}!" unless [ UsCountryArea, UsStateArea, UsZipArea ].include?(clazz)
  
  area = clazz.new
  @allowed_areas << area

  yield(area) if block_given?
  
  return area
end

#create_excluded_area(clazz) {|area| ... } ⇒ Object

Creates a new Area, adds it to the internal list of excluded areas for this shipping types. 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 { UsCountryArea, UsStateArea, UsZipArea }.

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

Yields:

  • (area)


489
490
491
492
493
494
495
496
497
498
# File 'lib/google4r/checkout/shared.rb', line 489

def create_excluded_area(clazz, &block)
  raise "Invalid Area class: #{clazz}!" unless [ UsCountryArea, UsStateArea, UsZipArea ].include?(clazz)

  area = clazz.new
  @excluded_areas << area
  
  yield(area) if block_given?
  
  return area
end