Publitas Backend Code Challenge

A product feed XML file (click to download).
Pick your language:
class ExternalService
  ONE_MEGA_BYTE = 1_048_576.0

  def initialize
    @batch_num = 0
  end

  def call(batch)
    @batch_num += 1
    pretty_print(batch)
  end

  private

  def pretty_print(batch)
    products = JSON.parse(batch)
    puts format("\e[1mReceived batch%4d\e[22m", @batch_num)
    puts format('Size: %10.4fMB', (batch.bytesize / ONE_MEGA_BYTE))
    puts format('Products: %8d', products.size)
    puts "\n"
  end
end
An imaginary external service (copy and paste).
const ONE_MEGA_BYTE = 1_048_576.0;

function prettyPrint(batch, batchNum) {
  const products = JSON.parse(batch);
  const batchSize = Buffer.byteLength(batch, 'utf8');
  const size = batchSize / ONE_MEGA_BYTE;

  console.log(`\x1b[1mReceived batch${String(batchNum).padStart(4)}\x1b[22m`);
  console.log(`Size: ${size.toFixed(4).padStart(10)}MB`);
  console.log(`Products: ${String(products.length).padStart(8)}`);
  console.log('\n');
}

export default function ExternalService() {
  let batchNum = 0;

  return {
    call(batch) {
      batchNum += 1;
      prettyPrint(batch, batchNum);
    },
  };
}
          
An imaginary external service (copy and paste).

The Task

Write a program that

A batch should

Deliverables

Please provide a GitHub repo with your code containing a README on how to build and run your assignment. The preferred way would be something like:

bundle install
ruby assignment.rb
npm install
node assignment.js

Extra Info