Guest User

Untitled

a guest
Feb 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class String
  2. def starts_with?(str)
  3. self =~ /#{str}/
  4. end
  5. end
  6.  
  7. names_to_edid = File.open(File.dirname(__FILE__) + '/edid_names').read.split("\n").
  8. collect {|line| edid, pruid, edname = line.split("|"); [edname.strip, edid.strip]}.
  9. inject({}) {|hash,e| hash[e.first] = e.last; hash }
  10.  
  11. lines = File.open(ARGV[0]).read.split("\n").inject({}) {|hash,e| pc, rest = e.split(','); hash[pc] = rest; hash}
  12.  
  13. lines.reject! {|k,v| v.nil?}
  14.  
  15. lines.each do |k,v|
  16. if v =~ /^[^a-z]*$/
  17. puts "#{k},#{v}"
  18. else
  19. begin
  20. edid = names_to_edid.detect {|name,edid| name.starts_with?(v)}.last
  21. puts k + "," + edid
  22. rescue
  23. puts "oops on [#{k},#{v}]"
  24. end
  25. end
  26. end
Add Comment
Please, Sign In to add comment