Csv

219 views

Published on

Un retour d'expérience sur comment traiter des fichiers CSV. C'est simple et basique, mais c'est mieux en le disant.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
219
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Csv

  1. 1. TOI AUSSI TRAITE DUCSV AVEC TON RUBYUn retour dexpérience
  2. 2. NICOLAS LEDEZOrange Business Services / IT&L@bsDevCamp RennesRennes On RailsRennes DevOpsGraphotec Cloud
  3. 3. JAI :Un fichier CSV de 600 lignesUne cible de 100 fichiers XML
  4. 4. CHOIX DES ARMESÀ la mainMacro VBA ExcelPerlPythonRuby
  5. 5. TDD 1/4
  6. 6. TDD 2/4
  7. 7. TDD 3/4
  8. 8. TDD 4/4
  9. 9. POUR COMMENCERdef parse_csv(filename)@list = {}lines = File.open(filename).readlineslines[1..-1].each { |line|(fullname, login) = line.chomp.split(";")
  10. 10. MAIS...def parse_csv(filename)@list = {}lines = File.open(filename).readlineslines[1..-1].each { |line|(firstname, lastname, login) = line.chomp.split(";")
  11. 11. 1 AN PLUS TARD+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Libraries | 446 | 356 | 6 | 19 | 3 | 16 || spec/vsabuilder | 484 | 388 | 0 | 38 | 0 | 8 |+----------------------+-------+-------+---------+---------+-----+-------+Code LOC: 356 Test LOC: 388 Code to Test Ratio: 1:1.1
  12. 12. LAGILITÉCest aussi savoir tout casser
  13. 13. UTILISER UNE LIB !def parse(csv_filename, key)key_symbol = key.to_symCSV.foreach(csv_filename, :col_sep =>;, :headers =>true, :header_converters => :symbol) do |line|current_key = line[key_symbol]@content[current_key] = lineendend
  14. 14. 3 JOURS APRÈS+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Libraries | 58 | 48 | 2 | 7 | 3 | 4 || spec/lib | 157 | 122 | 0 | 6 | 0 | 18 |+----------------------+-------+-------+---------+---------+-----+-------+Code LOC: 48 Test LOC: 122 Code to Test Ratio: 1:2.5Rappel :+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Libraries | 446 | 356 | 6 | 19 | 3 | 16 || spec/vsabuilder | 484 | 388 | 0 | 38 | 0 | 8 |+----------------------+-------+-------+---------+---------+-----+-------+Code LOC: 356 Test LOC: 388 Code to Test Ratio: 1:1.1
  15. 15. SOURCEShttps://github.com/nledez/csv2other
  16. 16. CONCLUSION
  17. 17. @NLEDEZ

×