Advertisement
cd62131

Minimums

Apr 8th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.56 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'yaml'
  3.  
  4. def parse_file(path)
  5.   body = File.read(path)
  6.     .gsub(/^\s*\d+\s*=>\s*/, '').delete('{},').strip
  7.   body.each_line.map {|e| { val: e.to_f, path: path } }
  8. end
  9.  
  10. min_data = Dir['file*'].map {|path| parse_file(path) }
  11.   .transpose
  12.   .map {|e| e.min_by {|v| [v[:val], v[:path]] } }
  13.  
  14. # simple
  15. open('simple.txt', 'w') {|f| min_data.each {|e| f.puts e } }
  16.  
  17. # with path
  18. open('withpath.txt', 'w') do |f|
  19.   min_data.each {|e| f.puts "#{e[:val]}, #{e[:path]}" }
  20. end
  21.  
  22. # yaml
  23. YAML.dump(min_data, File.open('result.yaml', 'w'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement