Module: Trackerific::Services

Defined in:
lib/trackerific/services.rb

Defined Under Namespace

Modules: Concerns Classes: Base, FedEx, MockService, UPS, USPS

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Finds a service by the given name

Parameters:

  • name (Symbol)

    The name of the service

Returns:

  • A descendant of Trackerific::Services::Base or nil for no match



10
11
12
# File 'lib/trackerific/services.rb', line 10

def [](name)
  @services[name]
end

.[]=(name, _class) ⇒ Object

Registers a service by the given name and class

Parameters:



18
19
20
21
22
23
24
25
26
# File 'lib/trackerific/services.rb', line 18

def []=(name, _class)
  unless _class.superclass == Trackerific::Services::Base
    raise ArgumentError,
      "Expected a Trackerific::Services::Base, got #{_class.inspect}",
      caller
  end

  @services[name] = _class
end

.find_by_package_id(id) ⇒ Array, Trackerific::Services::Base

Finds the tracking service(s) that are capable of tracking the given package ID capable of tracking the given ID.

Examples:

Find out which service providers can track a FedEx ID

Trackerific::Services.find_by_package_id "183689015000001"

Parameters:

  • id (String)

    The package identifier

Returns:



36
37
38
# File 'lib/trackerific/services.rb', line 36

def find_by_package_id(id)
  @services.map {|n,s| s if s.can_track?(id) }.compact
end