Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old Dominion support #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions couriers/old_dominion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "Old Dominion Freight Line",
"courier_code": "old_dominion",
"tracking_numbers": [
{
"name": "Old Dominion",
"regex": [
"\\s*(?<SerialNumber>",
"(7\\s*7\\s*[78]\\s*|0\\s*7\\s*2\\s*|7\\s*8\\s*0\\s*)",
"([0-9]\\s*){7}",
")",
"(?<CheckDigit>[0-9]\\s*)"
],
"validation": {
"checksum": {
"name": "luhn"
}
},
"tracking_url": "https://www.odfl.com/us/en/tools/trace-track-ltl-freight/trace.html?proNumbers=%s",
"test_numbers": {
"valid": [
"07209562763",
" 0 7 2 0 9 5 6 2 7 6 3 ",
"77767553207",
"77806528897",
"78045768393"
],
"invalid": [
"07209562773",
"79927398713",
"10000000000"
]
}
},
{
"name": "Old Dominion Guaranteed Shipment",
"regex": [
"\\s*(?<SerialNumber>",
"8\\s*0\\s*",
"([0-9]\\s*){8}",
")",
"(?<CheckDigit>[0-9]\\s*)"
],
"validation": {
"checksum": {
"name": "luhn"
}
},
"tracking_url": "https://www.odfl.com/us/en/tools/trace-track-ltl-freight/trace.html?proNumbers=%s",
"test_numbers": {
"valid": [
"80003280379",
" 8 0 0 0 3 2 8 0 3 7 9 ",
"80993847369"
],
"invalid": [
"80003280389",
"10000000000"
]
}
}
]
}
25 changes: 24 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ module TrackingNumber
module ChecksumValidations
class << self
# DEV NOTE: Add new checksum validation methods here while developing

def validates_luhn?(sequence, check_digit, extras = {})
total = 0
sequence.chars.reverse.each_with_index do |c, i|
x = c.to_i

if i.even?
x *= 2
end

if x > 9
x -= 9
end

total += x
end

check = (total % 10)
check = (10 - check) unless (check.zero?)

return (check.to_i == check_digit.to_i)
end

end
end
end
Expand Down Expand Up @@ -103,4 +126,4 @@ def should_fail_on_check_digit_changes(valid_number)
invalid_number = digits.join
t = TrackingNumber.new(invalid_number)
expect(t.valid?).to be_falsy, "#{invalid_number} reported as a valid #{t.class}, and it shouldn't be"
end
end
Loading