我有一个格式如下的 CSV 文件:
name,color,tasty,qty
apple,red,true,3
orange,orange,false,4
pear,greenish-yellowish,true,1
如您所见,Ruby OO 世界中的每一列都代表多种类型——字符串、字符串、布尔值、整数。
现在,最终,我想解析文件中的每一行,确定适当的类型,然后通过 Rails 迁移将该行插入到数据库中。例如:
Fruit.create(:name => 'apple', :color => 'red', :tasty => true, :qty => 3)
帮助!