Sha256: 2fb32937edb189b3902a2664a0f7c3c5a42069e457f5e2def6c7eba73285597c

Contents?: true

Size: 616 Bytes

Versions: 3

Compression:

Stored size: 616 Bytes

Contents

const mongoose = require('mongoose/browser');
const cql = require('cql-execution');

function Ratio(key, options) {
  mongoose.SchemaType.call(this, key, options, 'Ratio');
}
Ratio.prototype = Object.create(mongoose.SchemaType.prototype);

Ratio.prototype.cast = (ratio) => {
  if (typeof ratio.numerator === 'undefined') {
    throw new Error(`Ratio: ${ratio} does not have a numerator`);
  } else if (typeof ratio.denominator === 'undefined') {
    throw new Error(`Ratio: ${ratio} does not have a denominator`);
  }

  return new cql.Ratio(ratio);
};

mongoose.Schema.Types.Ratio = Ratio;
module.exports = Ratio;

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cqm-models-2.0.1 app/assets/javascripts/basetypes/Ratio.js
cqm-models-2.0.0 app/assets/javascripts/basetypes/Ratio.js
cqm-models-1.1.1.0 app/assets/javascripts/basetypes/Ratio.js