Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Add a runner for ruby #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ruby/runner.rb
Original file line number Diff line number Diff line change
@@ -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 <in-file> <out-file>"
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)