Class: FriendlyShipping::Services::Usps::RateEstimatePackageOptions

Inherits:
PackageOptions
  • Object
show all
Defined in:
lib/friendly_shipping/services/usps/rate_estimate_package_options.rb

Instance Attribute Summary collapse

Attributes inherited from PackageOptions

#package_id

Instance Method Summary collapse

Methods inherited from PackageOptions

#options_for_item

Constructor Details

#initialize(**kwargs) ⇒ RateEstimatePackageOptions

Returns a new instance of RateEstimatePackageOptions.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 27

def initialize(**kwargs)
  box_name = value_or_default(:box_name, :variable, kwargs)
  @box_name = CONTAINERS.key?(box_name) ? box_name : :variable
  @commercial_pricing = value_or_default(:commercial_pricing, false, kwargs)
  @first_class_mail_type = kwargs.delete(:first_class_mail_type)
  @hold_for_pickup = value_or_default(:hold_for_pickup, false, kwargs)
  @shipping_method = kwargs.delete(:shipping_method)
  @transmit_dimensions = value_or_default(:transmit_dimensions, true, kwargs)
  @rectangular = value_or_default(:rectangular, true, kwargs)
  @return_dimensional_weight = value_or_default(:return_dimensional_weight, true, kwargs)
  @return_fees = value_or_default(:return_fees, false, kwargs)
  super(**kwargs)
end

Instance Attribute Details

#box_nameObject (readonly)

Returns the value of attribute box_name.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def box_name
  @box_name
end

#commercial_pricingObject (readonly)

Returns the value of attribute commercial_pricing.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def commercial_pricing
  @commercial_pricing
end

#first_class_mail_typeObject (readonly)

Returns the value of attribute first_class_mail_type.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def first_class_mail_type
  @first_class_mail_type
end

#hold_for_pickupObject (readonly)

Returns the value of attribute hold_for_pickup.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def hold_for_pickup
  @hold_for_pickup
end

#rectangularObject (readonly)

Returns the value of attribute rectangular.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def rectangular
  @rectangular
end

#return_dimensional_weightObject (readonly)

Returns the value of attribute return_dimensional_weight.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def return_dimensional_weight
  @return_dimensional_weight
end

#return_feesObject (readonly)

Returns the value of attribute return_fees.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def return_fees
  @return_fees
end

#shipping_methodObject (readonly)

Returns the value of attribute shipping_method.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def shipping_method
  @shipping_method
end

#transmit_dimensionsObject (readonly)

Returns the value of attribute transmit_dimensions.



17
18
19
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 17

def transmit_dimensions
  @transmit_dimensions
end

Instance Method Details

#container_codeObject



41
42
43
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 41

def container_code
  CONTAINERS.fetch(box_name)
end

#first_class_mail_type_codeObject



45
46
47
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 45

def first_class_mail_type_code
  FIRST_CLASS_MAIL_TYPES[first_class_mail_type]
end

#service_codeObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/friendly_shipping/services/usps/rate_estimate_package_options.rb', line 49

def service_code
  return 'ALL' unless shipping_method

  # Cubic shipping methods don't have HFP or COMMERCIAL modifiers
  return shipping_method.service_code if shipping_method.service_code =~ /CUBIC/

  service_code = [shipping_method.service_code]
  service_code << 'HFP' if hold_for_pickup
  service_code << 'COMMERCIAL' if commercial_pricing
  service_code.join(' ')
end