Sha256: 926af19598d9af275a9a9ba513126d1533351dd388d9cbe611c3c3922e5a3177

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class USPSShip
      # USPS has certain size and weight requirements for packages to be considered
      # machinable. Machinable packages are generally less expensive to ship.
      # @see https://pe.usps.com/BusinessMail101?ViewName=Parcels
      #
      class MachinablePackage
        # @return [Physical::Package]
        attr_reader :package

        MIN_LENGTH = Measured::Length(6, :inches)
        MIN_WIDTH = Measured::Length(3, :inches)
        MIN_HEIGHT = Measured::Length(0.25, :inches)

        MAX_LENGTH = Measured::Length(27, :inches)
        MAX_WIDTH = Measured::Length(17, :inches)
        MAX_HEIGHT = Measured::Length(17, :inches)

        MAX_WEIGHT = Measured::Weight(25, :pounds)

        # @param package [Physical::Package]
        def initialize(package)
          @package = package
        end

        # @return [Boolean]
        def machinable?
          at_least_minimum && at_most_maximum
        end

        private

        # @return [Boolean]
        def at_least_minimum
          package.length >= MIN_LENGTH &&
            package.width >= MIN_WIDTH &&
            package.height >= MIN_HEIGHT
        end

        # @return [Boolean]
        def at_most_maximum
          package.length <= MAX_LENGTH &&
            package.width <= MAX_WIDTH &&
            package.height <= MAX_HEIGHT &&
            package.weight <= MAX_WEIGHT
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_shipping-0.9.0 lib/friendly_shipping/services/usps_ship/machinable_package.rb