Sha256: 56270153d046edf40fac4018034d9bfd46cc5706624bc99dfe351a99c3025ac1

Contents?: true

Size: 999 Bytes

Versions: 29

Compression:

Stored size: 999 Bytes

Contents

#!/usr/bin/env ruby

require 'yaml'
require 'json'
require 'optparse'
require 'ostruct'
require 'fileutils'

#quit unless our script gets two command line arguments
unless ARGV.length == 3
  puts "Dude, not the right number of arguments."
  puts "Usage: ruby YJ_Convert.rb [-j][-y] json_file.json yaml_file.yaml\n"
  exit
end

$json_file = ARGV[1]
$yaml_file = ARGV[2]

options = OpenStruct.new
OptionParser.new do |opt|
  opt.on('-j', '--json', 'Convert to JSON') { |o| options.json = o }
  opt.on('-y', '--yaml', 'Convert to YAML') { |o| options.yaml = o }
end.parse!

case
  when options.yaml == true
    y_file = File.open("#{$yaml_file}", 'a')
    y_file.write(YAML.dump(JSON.parse(IO.read($json_file))))
    y_file.close
    puts "Converted to YAML. Output file is #{$yaml_file}"

  when options.json == true
    j_file = YAML.load_file(File.open("#{$yaml_file}", 'r'))
    File.write "#{$json_file}", JSON.pretty_generate(j_file)
    puts "Converted to JSON. Output file is #{$json_file}"
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
scoutui-2.0.3.36.pre examples/converters/jsony.rb
scoutui-2.0.3.35.pre examples/converters/jsony.rb
scoutui-2.0.3.34.pre examples/converters/jsony.rb
scoutui-2.0.3.33.pre examples/converters/jsony.rb
scoutui-2.0.3.32.pre examples/converters/jsony.rb
scoutui-2.0.3.31.pre examples/converters/jsony.rb
scoutui-2.0.3.30.pre examples/converters/jsony.rb
scoutui-2.0.3.29.pre examples/converters/jsony.rb
scoutui-2.0.3.28.pre examples/converters/jsony.rb