Tab Spacing Ruby

时间:2017-05-08 11:14:23

标签: ruby tabs formatting spacing ruby-hash

我正在尝试使用Ruby脚本复制文件,我有一个包含文件内容的哈希,然后我使用JSON.pretty_generate将我生成的文件放在与原始文件相同的格式上,但间距不同。

这是原始文件:

{
    "ip-fileinput-collector": {
        "parameters": {
            "delete_file": false,
            "feed": "FileCollector",
            "provider": "MyFeed",
            "path": "/home/mf370/Desktop/",
            "postfix": "teste_ip.csv",
            "rate_limit": 300,
            "enabled": true
        },
        "group": "Collector",
        "name": "Fileinput",
        "module": "collector_file",
        "description": "Fileinput collector fetches data from a file."
    }
}

这是我程序的输出:

{
  "ip-fileinput-collector": {
    "parameters": {
      "delete_file": false,
      "feed": "FileCollector",
      "provider": "MyFeed",
      "path": "/home/mf370/Desktop/",
      "postfix": "teste_ip.csv",
      "rate_limit": 300,
      "enabled": true
    },
    "group": "Collector",
    "name": "Fileinput",
    "module": "collector_file",
    "description": "Fileinput collector fetches data from a file."
  }
}

我的代码是:

file_content = {"ip-fileinput-collector"=>{"parameters"=>{"delete_file"=>false, "feed"=>"FileCollector", "provider"=>"MyFeed", "path"=>"/home/mf370/Desktop/", "postfix"=>"teste_ip.csv", "rate_limit"=>300, "enabled"=>true}, "group"=>"Collector", "name"=>"Fileinput", "module"=>"collector_file", "description"=>"Fileinput collector fetches data from a file."}

require 'json'
File.open('my_file.conf','w+') do |f|
      f.write(JSON.pretty_generate(file_content))
end

Ruby中复制原始文件并具有相同间距的最佳方法是什么?

0 个答案:

没有答案