Class: PackageTracker::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/package_tracker/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracking_number, carrier, statuses = []) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
# File 'lib/package_tracker/response.rb', line 6

def initialize(tracking_number, carrier, statuses=[])
  @tracking_number = tracking_number
  @carrier = carrier
  @statuses = statuses
  sort_statuses!
end

Instance Attribute Details

#statusesObject (readonly)

Returns the value of attribute statuses.



3
4
5
# File 'lib/package_tracker/response.rb', line 3

def statuses
  @statuses
end

#tracking_numberObject (readonly)

Returns the value of attribute tracking_number.



4
5
6
# File 'lib/package_tracker/response.rb', line 4

def tracking_number
  @tracking_number
end

Instance Method Details

#add_status(message, time, location = "") ⇒ Object



13
14
15
16
# File 'lib/package_tracker/response.rb', line 13

def add_status(message, time, location="")
  @statuses << { :message => message, :time => time, :location => location }
  sort_statuses!
end

#current_locationObject



22
23
24
# File 'lib/package_tracker/response.rb', line 22

def current_location
  current_status[:location]
end

#current_statusObject



18
19
20
# File 'lib/package_tracker/response.rb', line 18

def current_status
  @statuses.first
end

#delivered?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/package_tracker/response.rb', line 26

def delivered?
  current_status[:message] == @carrier.delivered_status
end