Sha256: 13d79bc872c6baea7725f8adbaa441ae04317019e848cc28adb78372062ee834

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  class Rate
    class NoAmountsGiven < StandardError; end
    attr_reader :shipping_method,
                :amounts,
                :remote_service_id,
                :delivery_date,
                :warnings,
                :errors,
                :data

    # @param [FriendlyShipping::ShippingMethod] shipping_method The rate's shipping method
    # @param [Hash] amounts The amounts (as Money objects) that make up the rate
    # @param [Integer] remote_service_id The remote service ID for the rate
    # @param [Time] delivery_date The delivery date for the rate
    # @param [Array] warnings Any warnings that were generated
    # @param [Array] errors Any errors that were generated
    # @param [Hash] data Additional data related to the rate
    def initialize(
      shipping_method:,
      amounts:,
      remote_service_id: nil,
      delivery_date: nil,
      warnings: [],
      errors: [],
      data: {}
    )
      @remote_service_id = remote_service_id
      @shipping_method = shipping_method
      @amounts = amounts
      @delivery_date = delivery_date
      @warnings = warnings
      @errors = errors
      @data = data
    end

    def total_amount
      raise NoAmountsGiven if amounts.empty?

      amounts.map { |_name, amount| amount }.sum
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
friendly_shipping-0.7.3 lib/friendly_shipping/rate.rb
friendly_shipping-0.7.2 lib/friendly_shipping/rate.rb
friendly_shipping-0.7.1 lib/friendly_shipping/rate.rb
friendly_shipping-0.7.0 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.5 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.4 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.3 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.2 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.1 lib/friendly_shipping/rate.rb
friendly_shipping-0.6.0 lib/friendly_shipping/rate.rb
friendly_shipping-0.5.3 lib/friendly_shipping/rate.rb
friendly_shipping-0.5.2 lib/friendly_shipping/rate.rb
friendly_shipping-0.5.1 lib/friendly_shipping/rate.rb
friendly_shipping-0.5 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.14 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.13 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.12 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.11 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.10 lib/friendly_shipping/rate.rb
friendly_shipping-0.4.9 lib/friendly_shipping/rate.rb