Class: FriendlyShipping::Timing
- Inherits:
-
Object
- Object
- FriendlyShipping::Timing
- Defined in:
- lib/friendly_shipping/timing.rb
Overview
Base class for a transit timing estimate returned by a carrier API.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Additional data related to the timing.
-
#delivery ⇒ Time
readonly
The delivery estimate.
-
#errors ⇒ Array
readonly
Any errors that were generated.
-
#guaranteed ⇒ Boolean
readonly
Whether the delivery estimate is guaranteed.
-
#pickup ⇒ Time
readonly
The pickup estimate.
-
#properties ⇒ Hash
readonly
Additional data related to the timing (DEPRECATED: use
data
instead). -
#shipping_method ⇒ ShippingMethod
readonly
This timing's shipping method.
-
#warnings ⇒ Array
readonly
Any warnings that were generated.
Instance Method Summary collapse
-
#initialize(shipping_method:, pickup:, delivery:, guaranteed: false, warnings: [], errors: [], properties: {}, data: {}) ⇒ Timing
constructor
A new instance of Timing.
-
#time_in_transit ⇒ Time
Calculates and returns the time between pickup and delivery.
Constructor Details
#initialize(shipping_method:, pickup:, delivery:, guaranteed: false, warnings: [], errors: [], properties: {}, data: {}) ⇒ Timing
Returns a new instance of Timing.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/friendly_shipping/timing.rb', line 38 def initialize( shipping_method:, pickup:, delivery:, guaranteed: false, warnings: [], errors: [], properties: {}, data: {} ) @shipping_method = shipping_method @pickup = pickup @delivery = delivery @guaranteed = guaranteed @warnings = warnings @errors = errors @data = @properties = properties.presence || data warn "[DEPRECATION] `properties` is deprecated. Please use `data` instead." if properties.present? end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns additional data related to the timing.
28 29 30 |
# File 'lib/friendly_shipping/timing.rb', line 28 def data @data end |
#delivery ⇒ Time (readonly)
Returns the delivery estimate.
13 14 15 |
# File 'lib/friendly_shipping/timing.rb', line 13 def delivery @delivery end |
#errors ⇒ Array (readonly)
Returns any errors that were generated.
22 23 24 |
# File 'lib/friendly_shipping/timing.rb', line 22 def errors @errors end |
#guaranteed ⇒ Boolean (readonly)
Returns whether the delivery estimate is guaranteed.
16 17 18 |
# File 'lib/friendly_shipping/timing.rb', line 16 def guaranteed @guaranteed end |
#pickup ⇒ Time (readonly)
Returns the pickup estimate.
10 11 12 |
# File 'lib/friendly_shipping/timing.rb', line 10 def pickup @pickup end |
#properties ⇒ Hash (readonly)
Returns additional data related to the timing (DEPRECATED: use data
instead).
25 26 27 |
# File 'lib/friendly_shipping/timing.rb', line 25 def properties @properties end |
#shipping_method ⇒ ShippingMethod (readonly)
Returns this timing's shipping method.
7 8 9 |
# File 'lib/friendly_shipping/timing.rb', line 7 def shipping_method @shipping_method end |
#warnings ⇒ Array (readonly)
Returns any warnings that were generated.
19 20 21 |
# File 'lib/friendly_shipping/timing.rb', line 19 def warnings @warnings end |
Instance Method Details
#time_in_transit ⇒ Time
Calculates and returns the time between pickup and delivery.
60 61 62 |
# File 'lib/friendly_shipping/timing.rb', line 60 def time_in_transit delivery - pickup end |