Class: ANLExpress::TrackingStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/anlexpress/tracking_status.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ta) ⇒ TrackingStatus

Returns a new instance of TrackingStatus.



10
11
12
13
# File 'lib/anlexpress/tracking_status.rb', line 10

def initialize(ta)
  @tracking_number = ta
  @status=[]
end

Instance Attribute Details

#carrierObject

Returns the value of attribute carrier.



7
8
9
# File 'lib/anlexpress/tracking_status.rb', line 7

def carrier
  @carrier
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/anlexpress/tracking_status.rb', line 8

def status
  @status
end

#tracking_numberObject

Returns the value of attribute tracking_number.



7
8
9
# File 'lib/anlexpress/tracking_status.rb', line 7

def tracking_number
  @tracking_number
end

#updateObject

Returns the value of attribute update.



7
8
9
# File 'lib/anlexpress/tracking_status.rb', line 7

def update
  @update
end

Class Method Details

.create_statues(delegate, *track_numbers, &block) ⇒ Object



51
52
53
54
55
# File 'lib/anlexpress/tracking_status.rb', line 51

def self.create_statues delegate, *track_numbers, &block
  tracking_status = delegate.create_statues(track_numbers)
  update_status!(*tracking_status, &block)
  tracking_status
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/anlexpress/tracking_status.rb', line 30

def == (other)
  other.class == self.class && @tracking_number == other.tracking_number && @status == other.status
end

#add_status(date, note) ⇒ Object



15
16
17
# File 'lib/anlexpress/tracking_status.rb', line 15

def add_status(date, note)
  @status.push([date, note])
end

#to_sObject



23
24
25
26
27
28
29
# File 'lib/anlexpress/tracking_status.rb', line 23

def to_s
  s = ""
  s <<  @tracking_number.to_s << ":\n"
  @status.each{|v| 
    s << v[0].to_s << ":" << v[1] << "\n"
  }
end

#to_yaml_propertiesObject



19
20
21
# File 'lib/anlexpress/tracking_status.rb', line 19

def to_yaml_properties
  ["@tracking_number", "@status", "@carrier"]
end

#update?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/anlexpress/tracking_status.rb', line 34

def update?
  @update
end

#update_status! {|_self, self != old_tracking| ... } ⇒ Object

Yields:

  • (_self, self != old_tracking)

Yield Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/anlexpress/tracking_status.rb', line 38

def update_status!
  file = "#{TRACKING_FOLDER}/#{@tracking_number}.#{@carrier.code}.yaml"
  begin
      old_tracking =  YAML.load(File.open(file, "rb").read)
  rescue
  end
  if self != old_tracking
    File.open(file, 'w') { |file| file.write(self.to_yaml)}
  end
  yield(self,self != old_tracking)  if block_given?
  @update = self != old_tracking
end