Class: UspsApi::ShippingFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/usps_api/models/shipping_filter.rb

Overview

A filter for domestic results to return only one response based on lowest price or fastest service standard

Constant Summary collapse

SHIPPING_FILTER =
[
  # TODO: Write general description for PRICE
  PRICE = 'PRICE'.freeze,

  # TODO: Write general description for SERVICE_STANDARDS
  SERVICE_STANDARDS = 'SERVICE_STANDARDS'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = PRICE) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/usps_api/models/shipping_filter.rb', line 24

def self.from_value(value, default_value = PRICE)
  return default_value if value.nil?

  str = value.to_s.strip

  case str.downcase
  when 'price' then PRICE
  when 'service_standards' then SERVICE_STANDARDS
  else
    default_value
  end
end

.validate(value) ⇒ Object



18
19
20
21
22
# File 'lib/usps_api/models/shipping_filter.rb', line 18

def self.validate(value)
  return false if value.nil?

  SHIPPING_FILTER.include?(value)
end