ruby—从yaml文件读取设置,并根据rb文件的哈希返回

olqngx59  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(213)

我有这个:

require 'yaml'

input = [
  {
    name: 'Maria Neusa de Aparecida',
    cpf: '97905796671',
    state: 'Sao Paulo',
    value: '1234'
  },
  {
    name: 'Ricardo Fontes',
    cpf: '44010762900',
    state: 'Rio Grande do Sul',
    value: '567'
  }
 ]

 def solution(hash)
  # some solution input + yaml config I guess
 end

read = YAML.load_file('format-1.yaml')

puts read.inspect

在我的yaml文件中,我有:

cpf:
 length: 11
 align: left
 padding: spaces
name:
 length: 14
 align: left
 padding: spaces
value:
 length: 8
 align: right
 padding: zeroes

如何将输出配置为如下所示:

"97905796671Maria Neusa de00001234\n44010762900Ricardo Fontes00000567"

到目前为止,我只能读取yaml文件,但我不知道如何继续…:(
目前,我的输出如下:

{"cpf"=>{"length"=>11, "align"=>"left", "padding"=>"spaces"}, "name"=>{"length"=>14, "align"=>"left", "padding"=>"spaces"}, "value"=>{"length"=>8, "align"=>"right", "padding"=>"zeroes"}}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题