1
0

Implement formatter

This commit is contained in:
Tim Kächele 2024-08-25 10:03:39 +02:00
parent 1f3e21b711
commit d007829208
2 changed files with 18 additions and 0 deletions

View File

@ -5,6 +5,7 @@ require_relative "planet_express_express/constants"
require_relative "planet_express_express/shipment_reader" require_relative "planet_express_express/shipment_reader"
require_relative "planet_express_express/rules" require_relative "planet_express_express/rules"
require_relative "planet_express_express/discount_budget" require_relative "planet_express_express/discount_budget"
require_relative "planet_express_express/formatter"
module PlanetExpressExpress module PlanetExpressExpress
class Error < StandardError; end class Error < StandardError; end

View File

@ -0,0 +1,17 @@
module PlanetExpressExpress
class Formatter
def initialize(io)
@io = io
end
def format(shipments)
shipments[:all].each do |month|
month.each do |shipment|
@io.write(
"#{shipment[:date].iso8601} #{shipment[:size]} #{shipment[:provider]} #{(shipment[:price] - shipment[:discount]).to_s.rjust(3, "0").insert(-3, ".")} #{shipment[:discount].zero? ? "-" : shipment[:discount].to_s.rjust(3, "0").insert(-3, ".")}\n"
)
end
end
end
end
end