我正在寻找用 ruby 打印出一个 CSV 文件,但我想让它格式化。有没有办法在层次结构意义上格式化数据?这是我需要完成的清单的一小部分:
,"11: Agriculture, Forestry, Fishing and Hunting",,
,,"111: Crop Production",
,,,"111110: Soybean Farming"
,,,"111120: Oilseed (except Soybean) Farming"
,,,"111130: Dry Pea and Bean Farming"
,,,"111140: Wheat Farming"
,,"112: Animal Production",
,,,"112111: Beef Cattle Ranching and Farming"
,,,"112112: Cattle Feedlots"
,,,"112120: Dairy Cattle and Milk Production"
,,,"112130: Dual-Purpose Cattle Ranching and Farming"
我的代码是:
require 'csv'
col_data = []
CSV.foreach("primary_NAICS_code.txt") {|row| col_data << row}
puts col_data
这只是打印出所有内容。它是一个数组吗?就像是:
CSV.foreach do |row|
row.each do |line|
puts line
end
end
任何帮助都会为我指明正确的方向。
我想将信息格式化为如下所示:
|_ <~~ row 1 column 1
| |__<~ row 1 column 2
| | |__<~row 2 column 2
| | | |__
| | | | |__ etc...
| | | | | |__