Sha256: 8b31bcf9afa51f150889e736f9d31c724acd61cdb9a1d34d325bf2dc388d73b1

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

# frozen_string_literal: true

module SolidusEasypost
  class ParcelDimension
    def initialize(**params)
      raise ArgumentError, 'The weight param is mandatory!' unless valid_value?(value: params[:weight])

      @weight = params[:weight]
      @width = params[:width]
      @height = params[:height]
      @depth = params[:depth]
    end

    def to_h
      hash = {
        weight: weight
      }

      hash[:width] = width if valid_value?(value: width)
      hash[:height] = height if valid_value?(value: height)
      hash[:length] = depth if valid_value?(value: depth)

      hash
    end

    private

    def valid_value?(value:)
      value.present? && !value.zero?
    end

    attr_reader :width, :height, :depth, :weight
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_easypost-3.0.0 app/models/solidus_easypost/parcel_dimension.rb