Sha256: 0562706de5b6a9a5c1c55b526a02c11546b4c5112d640a0c28f5b5aade6b2538

Contents?: true

Size: 369 Bytes

Versions: 4

Compression:

Stored size: 369 Bytes

Contents

module CorreiosApi
  class ShippingQuotes
    attr_reader :rates
    def initialize rates
      @rates = rates
    end

    def cheaper_rate
      valid_rates.min_by(&:price)
    end

    def faster_rate
      valid_rates.min_by(&:delivery_time_in_days)
    end

    def valid_rates
      @rates.select { |rate| rate.price > 0 && rate.errors.empty? }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
correios_api-1.0.3 lib/correios_api/shipping_quotes.rb
correios_api-1.0.2 lib/correios_api/shipping_quotes.rb
correios_api-1.0.1 lib/correios_api/shipping_quotes.rb
correios_api-1.0.0 lib/correios_api/shipping_quotes.rb