Skip to content

Instantly share code, notes, and snippets.

@technion
Created March 28, 2019 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/1b017adf92fb99022caa6a45b6bd9b87 to your computer and use it in GitHub Desktop.
Save technion/1b017adf92fb99022caa6a45b6bd9b87 to your computer and use it in GitHub Desktop.
#!/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