红宝石代码段,用于读取线条块

时间:2019-04-28 18:05:29

标签: ruby yaml

我是红宝石的新手,正在寻求帮助。 我们得到的csv文件具有列,其数据如下所示。使用csv解析器并获取变量中每个列的数据。

我们想将列数据从csv文件更改为如下所示的行并写入文件:

---
- - status
  - New
  - Delivered

TO

status from New to Delivered

感谢@igian

---
- - status
  - New
  - Delivered
- - Milestone
  - Sprint1
  - Sprint

我为此而苦苦挣扎。我尝试使用y.second,但失败,请更正我做错的事情。

1 个答案:

答案 0 :(得分:3)

看起来像YAML文件,请参见https://ruby-doc.org/stdlib-2.6.2/libdoc/yaml/rdoc/YAML.html

加载文件,然后处理数组:

require 'yaml'

y = YAML.load_file( 'the_file.yaml' )
y #=> [["status", "New", "Delivered"]]

words = y.first
p "#{words[0]} from #{words[1]} to #{words[2]}"
#=> "status from New to Delivered"
相关问题