lib/base.rb in tracking_number-0.3.0 vs lib/base.rb in tracking_number-0.3.1
- old
+ new
@@ -4,15 +4,27 @@
def initialize(tracking_number)
@original_number = tracking_number
@tracking_number = tracking_number.gsub(" ", "").upcase
end
- def self.search(body)
- self.scan(body).uniq.collect { |possible| new(possible) }.select { |t| t.valid? }
+ def self.search(body)
+ valids = self.scan(body).uniq.collect { |possible| new(possible) }.select { |t| t.valid? }
+
+ uniques = {}
+ valids.each do |t|
+ uniques[t.tracking_number] = t unless uniques.has_key?(t.tracking_number)
+ end
+
+ uniques.values
end
def self.scan(body)
- possibles = body.scan(self.const_get("SEARCH_PATTERN")).uniq.flatten
+ patterns = [self.const_get("SEARCH_PATTERN")].flatten
+ possibles = patterns.collect do |pattern|
+ body.scan(pattern).uniq.flatten
+ end
+
+ possibles.flatten.compact.uniq
end
def valid?
return false unless valid_format?
return false unless valid_checksum?
\ No newline at end of file