Class: Cargowise::AbstractResult

Inherits:
Object
  • Object
show all
Defined in:
lib/cargowise/abstract_result.rb

Overview

Superclass of all objects built to contain results from the API. Not much to see here, mostly common helper methods for parsing values out of the XML response.

Direct Known Subclasses

Consol, Document, Invoice, Order, Packing, Shipment

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.endpoint(name) ⇒ Object



16
17
18
19
# File 'lib/cargowise/abstract_result.rb', line 16

def self.endpoint(name)
  @endpoints ||= {}
  @endpoints[name]
end

.register(name, opts = {}) ⇒ Object

:nodoc:



11
12
13
14
# File 'lib/cargowise/abstract_result.rb', line 11

def self.register(name, opts = {})
  @endpoints ||= {}
  @endpoints[name] = Endpoint.new(opts)
end

.via(name) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
# File 'lib/cargowise/abstract_result.rb', line 21

def self.via(name)
  @endpoints ||= {}
  raise ArgumentError, "#{name} is not recognised, have you registered it?" if @endpoints[name].nil?

  klass_name = (self.name[/Cargowise::(.+)/,1] + "Search")
  search_klass = Cargowise.const_get(klass_name)
  search_klass.new(@endpoints[name])
end

Instance Method Details

#inspectObject



30
31
32
33
34
35
# File 'lib/cargowise/abstract_result.rb', line 30

def inspect
  str = "<#{self.class}: "
  str << inspectable_vars.map { |v| "#{v.to_s.tr('@','')}: #{instance_variable_get(v)}" }.join(" ")
  str << ">"
  str
end