From 4bd82bf5eb2dff0b0f8553298fca1811dc978ec4 Mon Sep 17 00:00:00 2001 From: Glen Mailer Date: Tue, 12 Mar 2019 09:32:13 +0000 Subject: [PATCH] Add a runner for ruby --- ruby/runner.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ruby/runner.rb diff --git a/ruby/runner.rb b/ruby/runner.rb new file mode 100644 index 0000000000..32ada7c2ac --- /dev/null +++ b/ruby/runner.rb @@ -0,0 +1,32 @@ +#!/usr/bin/ruby -w + +require 'fileutils' + +require File.join(File.dirname(__FILE__), 'gilded_rose') + +if ARGV.length != 2 + puts "Usage: ruby runner.rb " + exit 1 +end + +in_file, out_file = ARGV + +puts "Reading from #{in_file}, writing to #{out_file}" + +items = IO.readlines(in_file) + .map(&:strip) + .reject { |l| l.empty? || l.start_with?(";") } + .map { |l| l.split("__") } + .map { |name, sell_in, quality| + Item.new(name, sell_in.to_i, quality.to_i) + } + +rose = GildedRose.new(items) +rose.update_quality + +output = items + .map { |i| [i.name, i.sell_in, i.quality].join("__") } + .join("\n") + +FileUtils.mkdir_p(File.dirname(out_file)) +IO.write(out_file, output)