Convert YAML to CSV (and backward)
Ruby
Switch branches/tags
Nothing to show
Latest commit f5fae44 Sep 20, 2016 @tokland committed on GitHub Merge pull request #6 from AlexVPopov/patch-2
Use comma as a field separator

README.markdown

Yaml2Csv

Transform YAML file into CSV and backwards. CSV files contain triplets [path, key, value]. For example:

path1:
  path11:
    key11a: value11a
    key11b: value11b
  path12:
    path121:
      key121a: value121a
path2:
  key2a: value2a

Will be converted into:

path1/path11,key11a,value11a
path1/path11,key11b,value11b
path1/path12/path121,key121a,value121a
path2,key2a,value2a

Only YAML files containing hashes and string values are supported (that includes most I18n YML files). Non-string values (i.e. arrays, booleans) are allowed, but will be treated as strings and its format will be lost.

Usage

As Ruby module

require 'yaml2csv'
Yaml2csv::yaml2csv(string, :field_separator => ',')
Yaml2csv::csv2yaml(string)

From command line

Convert file.yaml into CSV format:

$ yaml2csv_conv file.yml

Convert file.csv into YAML format (using ',' as field separator)

$ yaml2csv_conv -f"," -r file.csv