Class: Cargowise::Shipment
- Inherits:
-
AbstractResult
- Object
- AbstractResult
- Cargowise::Shipment
- Defined in:
- lib/cargowise/shipment.rb
Overview
A shipment that is currently on its way to you. Could take on a variety of forms - carton, palet, truck? Could be travelling via air, sea, road, rail, donkey?
Typcially you will lookup the status of a shipment you’re aware of using the shipment number:
Shipment.find_by_shipment_number(...)
If you want all recent shipments (delivered and undelivered) to ensure you know what’s coming:
Shipment.find_with_recent_activity(...)
All shipment objects are read-only, see the object attributes to see what information is available.
Instance Attribute Summary collapse
-
#client_reference ⇒ Object
readonly
Returns the value of attribute client_reference.
-
#consignee_name ⇒ Object
readonly
Returns the value of attribute consignee_name.
-
#consols ⇒ Object
readonly
Returns the value of attribute consols.
-
#cubic_meters ⇒ Object
readonly
Returns the value of attribute cubic_meters.
-
#delivered_date ⇒ Object
readonly
Returns the value of attribute delivered_date.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#eta ⇒ Object
readonly
Returns the value of attribute eta.
-
#etd ⇒ Object
readonly
Returns the value of attribute etd.
-
#goods_description ⇒ Object
readonly
Returns the value of attribute goods_description.
-
#housebill ⇒ Object
readonly
Returns the value of attribute housebill.
-
#invoices ⇒ Object
readonly
Returns the value of attribute invoices.
-
#kg ⇒ Object
readonly
Returns the value of attribute kg.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#packings ⇒ Object
readonly
Returns the value of attribute packings.
-
#service_level ⇒ Object
readonly
Returns the value of attribute service_level.
-
#shipper_name ⇒ Object
readonly
Returns the value of attribute shipper_name.
Instance Method Summary collapse
-
#initialize(node) ⇒ Shipment
constructor
A new instance of Shipment.
-
#order_ref(via) ⇒ Object
if this shipment has an order ref associated with it, find it.
-
#orders(via) ⇒ Object
lookup full Cargowise::Order objects for each order on this shipment.
-
#related_shipments(via) ⇒ Object
lookup related Cargowise::Shipment objects.
-
#to_xml ⇒ Object
returns the raw XML string this shipment is based on.
-
#transport_mode ⇒ Object
returns a space separated string with all transport modes being used to move this shipment.
Methods inherited from AbstractResult
endpoint, #inspect, register, via
Constructor Details
#initialize(node) ⇒ Shipment
Returns a new instance of Shipment.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cargowise/shipment.rb', line 35 def initialize(node) @node = node @number = text_value("./Number") @housebill = text_value("./HouseBill") @goods_description = text_value("./GoodsDescription") @service_level = text_value("./ServiceLevel") @client_reference = text_value("./ClientReference") @origin = text_value("./Origin") @destination = text_value("./Destination") @etd = time_value("./ETD") @eta = time_value("./ETA") @delivered_date = time_value("./DeliveredDate") @kg = kg_value("./Weight") @cubic_meters = cubic_value("./Size") @shipper_name = text_value("./Shipper/OrganisationDetails/Name") @consignee_name = text_value("./Consignee/OrganisationDetails/Name") @consols = node_array("./Consols/Consol").map { |node| Consol.new(node) } @packings = node_array("./Packings/Packing").map { |node| Packing.new(node) } @documents = node_array("./DocumentLinks/DocumentLink").map { |node| Document.new(node) }.sort_by { |doc| doc.date } @invoices = node_array("./RelatedInvoiceLinks/InvoiceLink").map { |node| Invoice.new(node) }.sort_by { |inv| inv.due_date } end |
Instance Attribute Details
#client_reference ⇒ Object (readonly)
Returns the value of attribute client_reference.
25 26 27 |
# File 'lib/cargowise/shipment.rb', line 25 def client_reference @client_reference end |
#consignee_name ⇒ Object (readonly)
Returns the value of attribute consignee_name.
31 32 33 |
# File 'lib/cargowise/shipment.rb', line 31 def consignee_name @consignee_name end |
#consols ⇒ Object (readonly)
Returns the value of attribute consols.
33 34 35 |
# File 'lib/cargowise/shipment.rb', line 33 def consols @consols end |
#cubic_meters ⇒ Object (readonly)
Returns the value of attribute cubic_meters.
27 28 29 |
# File 'lib/cargowise/shipment.rb', line 27 def cubic_meters @cubic_meters end |
#delivered_date ⇒ Object (readonly)
Returns the value of attribute delivered_date.
26 27 28 |
# File 'lib/cargowise/shipment.rb', line 26 def delivered_date @delivered_date end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
26 27 28 |
# File 'lib/cargowise/shipment.rb', line 26 def destination @destination end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
33 34 35 |
# File 'lib/cargowise/shipment.rb', line 33 def documents @documents end |
#eta ⇒ Object (readonly)
Returns the value of attribute eta.
26 27 28 |
# File 'lib/cargowise/shipment.rb', line 26 def eta @eta end |
#etd ⇒ Object (readonly)
Returns the value of attribute etd.
26 27 28 |
# File 'lib/cargowise/shipment.rb', line 26 def etd @etd end |
#goods_description ⇒ Object (readonly)
Returns the value of attribute goods_description.
24 25 26 |
# File 'lib/cargowise/shipment.rb', line 24 def goods_description @goods_description end |
#housebill ⇒ Object (readonly)
Returns the value of attribute housebill.
24 25 26 |
# File 'lib/cargowise/shipment.rb', line 24 def housebill @housebill end |
#invoices ⇒ Object (readonly)
Returns the value of attribute invoices.
33 34 35 |
# File 'lib/cargowise/shipment.rb', line 33 def invoices @invoices end |
#kg ⇒ Object (readonly)
Returns the value of attribute kg.
27 28 29 |
# File 'lib/cargowise/shipment.rb', line 27 def kg @kg end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
24 25 26 |
# File 'lib/cargowise/shipment.rb', line 24 def number @number end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
26 27 28 |
# File 'lib/cargowise/shipment.rb', line 26 def origin @origin end |
#packings ⇒ Object (readonly)
Returns the value of attribute packings.
33 34 35 |
# File 'lib/cargowise/shipment.rb', line 33 def packings @packings end |
#service_level ⇒ Object (readonly)
Returns the value of attribute service_level.
24 25 26 |
# File 'lib/cargowise/shipment.rb', line 24 def service_level @service_level end |
#shipper_name ⇒ Object (readonly)
Returns the value of attribute shipper_name.
29 30 31 |
# File 'lib/cargowise/shipment.rb', line 29 def shipper_name @shipper_name end |
Instance Method Details
#order_ref(via) ⇒ Object
if this shipment has an order ref associated with it, find it.
This data isn’t available via the API, so we need to screen scrape the website to get it.
118 119 120 121 122 123 124 |
# File 'lib/cargowise/shipment.rb', line 118 def order_ref(via) if tracker_login_uri(via) @order_ref ||= html_page(via).search(".//span[@id='Ztextlabel1']/text()").to_s.strip || "" else nil end end |
#orders(via) ⇒ Object
lookup full Cargowise::Order objects for each order on this shipment.
‘via’ is a symbol indicating which API endpoint to lookup.
93 94 95 |
# File 'lib/cargowise/shipment.rb', line 93 def orders(via) @orders ||= Cargowise::Order.via(via).by_shipment_number(self.number) end |
#related_shipments(via) ⇒ Object
lookup related Cargowise::Shipment objects. These are usually “child” shipments grouped under a parent. Think a consolidated pallet (the parent) with cartons from multiple suppliers (the children).
‘via’ is a symbol indicating which API endpoint to lookup.
103 104 105 106 107 108 109 110 111 |
# File 'lib/cargowise/shipment.rb', line 103 def (via) @related ||= @consols.map { |consol| consol.master_bill }.compact.map { |master_bill| Cargowise::Shipment.via(via).by_masterbill_number(master_bill) }.flatten.select { |shipment| shipment.number != self.number }.compact end |
#to_xml ⇒ Object
returns the raw XML string this shipment is based on
78 79 80 |
# File 'lib/cargowise/shipment.rb', line 78 def to_xml @node.to_xml end |
#transport_mode ⇒ Object
returns a space separated string with all transport modes being used to move this shipment
85 86 87 |
# File 'lib/cargowise/shipment.rb', line 85 def transport_mode @consols.map { |con| con.transport_mode }.uniq.sort.join(" ") end |