Sha256: 4fc83cf3525b0f9a8528c016f5176f1d6c1a90f42599af9ad8d20376209f0aba

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module FreightKit
  class Tariff
    attr_accessor :overlength_rules

    def initialize(options = {})
      options.symbolize_keys!
      @options = options

      @options[:overlength_rules] = (@options[:overlength_rules].presence || [])
      raise ArgumentError, 'overlength_rules must be an Array' unless @options[:overlength_rules].is_a?(Array)

      @options[:overlength_rules].each do |overlength_rule|
        if !overlength_rule[:min_length].is_a?(Measured::Length)
          raise ArgumentError, 'overlength_rule[:min_length] must be a Measured::Length'
        elsif ![Measured::Length, NilClass].include?(overlength_rule[:max_length].class)
          raise ArgumentError, 'overlength_rule[:max_length] must be one of Measured::Length, NilClass'
        end

        unless overlength_rule[:fee_cents].is_a?(Integer)
          raise ArgumentError, 'overlength_rule[:fee_cents] must be an Integer'
        end
      end

      @overlength_rules = @options[:overlength_rules]
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
freight_kit-0.1.11 lib/freight_kit/tariff.rb
freight_kit-0.1.10 lib/freight_kit/tariff.rb
freight_kit-0.1.7 lib/freight_kit/tariff.rb
freight_kit-0.1.4 lib/freight_kit/tariff.rb
freight_kit-0.1.3 lib/freight_kit/tariff.rb
freight_kit-0.1.2 lib/freight_kit/tariff.rb
freight_kit-0.1.1 lib/freight_kit/tariff.rb
freight_kit-0.1.0 lib/freight_kit/tariff.rb