Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. require 'csv'
  2.  
  3. lines_for_output = []
  4.  
  5. CSV.foreach("momoda.csv") do |row|
  6. row_text = row[0] + row[1]
  7.  
  8. line = {}
  9.  
  10. line[:rank] = row_text.scan(/.*位/).first
  11. line[:bank_name] = row_text.split(/.*位/, 2)[1].gsub(/[\d]/, "")
  12. line[:amount] = row_text.split(/.*位/, 2)[1].gsub(/[^\d]/, "")
  13.  
  14. lines_for_output << line
  15. end
  16.  
  17. CSV.open('momoda_new_list.csv','w') do |csv|
  18. lines_for_output.each do |line|
  19. csv << [
  20. line[:rank],line[:bank_name],line[:amount]
  21. ]
  22. end
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement