2021-03-05 21:00:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'bundler/gem_tasks'
|
|
|
|
require 'rspec/core/rake_task'
|
2021-03-07 22:16:25 +01:00
|
|
|
require 'planet_express'
|
2021-03-05 21:00:31 +01:00
|
|
|
|
|
|
|
RSpec::Core::RakeTask.new(:spec)
|
|
|
|
|
|
|
|
task default: :spec
|
2021-03-07 22:16:25 +01:00
|
|
|
|
2021-03-08 11:14:47 +01:00
|
|
|
task :process, [:input_file] do |_t, args|
|
2021-03-07 22:16:25 +01:00
|
|
|
file = File.open(args.input_file, 'r')
|
|
|
|
|
2021-03-08 11:14:47 +01:00
|
|
|
shipping_option_repository = PlanetExpress::ShippingOptionRepository.new
|
2021-03-07 22:16:25 +01:00
|
|
|
shipment_repository = PlanetExpress::ShipmentRepository.new(data: [])
|
|
|
|
discount_budget_for_month_repository = PlanetExpress::DiscountBudgetForMonthRepository.new
|
|
|
|
|
|
|
|
shipment_reader = PlanetExpress::ShipmentReader.new(file, shipping_option_repository)
|
|
|
|
shipment_formatter = PlanetExpress::ShipmentFormatter.new
|
|
|
|
|
|
|
|
rules = [
|
|
|
|
PlanetExpress::SShipmentDiscountRule.new(
|
|
|
|
discount_budget_for_month_repository: discount_budget_for_month_repository,
|
|
|
|
shipping_option_repository: shipping_option_repository,
|
2021-03-08 11:14:47 +01:00
|
|
|
shipment_repository: shipment_repository
|
|
|
|
),
|
2021-03-07 22:16:25 +01:00
|
|
|
PlanetExpress::LShipmentDiscountRule.new(
|
|
|
|
discount_budget_for_month_repository: discount_budget_for_month_repository,
|
|
|
|
shipping_option_repository: shipping_option_repository,
|
2021-03-08 11:14:47 +01:00
|
|
|
shipment_repository: shipment_repository
|
|
|
|
)
|
2021-03-07 22:16:25 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
PlanetExpress::ShipmentDiscountCalculator.new(
|
|
|
|
shipment_repository: shipment_repository,
|
2021-03-08 11:14:47 +01:00
|
|
|
rules: rules
|
|
|
|
).run(shipment_reader)
|
2021-03-07 22:16:25 +01:00
|
|
|
|
|
|
|
shipment_repository.each do |shipment|
|
|
|
|
puts shipment_formatter.format(shipment)
|
|
|
|
end
|
|
|
|
end
|