Created
March 28, 2019 05:19
-
-
Save technion/1b017adf92fb99022caa6a45b6bd9b87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
INTEST = '5 10 20 50-60 70-73 75-79 80 95'.freeze | |
OUTTEST = '5 10 20 50 51 52 53 54 55 56 57 58 59 60 70 71 72 73 75 76 77 78 79 80 95'.freeze | |
def rangeconvert(r) | |
start, finish = r.scan(/\d+/) | |
raise "Invalid input" unless start < finish | |
(start..finish).to_a.join(' ') | |
end | |
def vlanconvert(vlans) | |
vlans.gsub(/\d+-\d+/) { |s| rangeconvert(s) } | |
end | |
outputtest = vlanconvert(INTEST) | |
raise "failed" unless outputtest == OUTTEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment