Implement formatter
This commit is contained in:
parent
1f3e21b711
commit
d007829208
@ -5,6 +5,7 @@ require_relative "planet_express_express/constants"
|
||||
require_relative "planet_express_express/shipment_reader"
|
||||
require_relative "planet_express_express/rules"
|
||||
require_relative "planet_express_express/discount_budget"
|
||||
require_relative "planet_express_express/formatter"
|
||||
|
||||
module PlanetExpressExpress
|
||||
class Error < StandardError; end
|
||||
|
17
lib/planet_express_express/formatter.rb
Normal file
17
lib/planet_express_express/formatter.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user