Class: Trackerific::Services::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/trackerific/services/base.rb

Direct Known Subclasses

FedEx, MockService, UPS, USPS

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/trackerific/services/base.rb', line 5

def name
  @name
end

Class Method Details

.can_track?(id) ⇒ Boolean

Checks if the given package ID can be tracked by this service

Parameters:

  • id (String)

    The package ID

Returns:

  • (Boolean)

    true when this service can track the given ID



22
23
24
25
# File 'lib/trackerific/services/base.rb', line 22

def can_track?(id)
  package_id_matchers.each {|m| return true if id =~ m }
  false
end

.package_id_matchersObject

An Array of Regexp that matches valid package ids for the service

Raises:

  • (NotImplementedError)


29
30
31
32
# File 'lib/trackerific/services/base.rb', line 29

def package_id_matchers
  raise NotImplementedError,
    "You must implement this method in your service", caller
end

.register(name) ⇒ Object

Registers the service with Trackerific



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

def register(name)
  self.name = name.to_sym
  Trackerific::Services[self.name] = self
end

.track(id) ⇒ Object



14
15
16
17
# File 'lib/trackerific/services/base.rb', line 14

def track(id)
  options = Trackerific.configuration[self.name] || {}
  new(options).track(id)
end