Sha256: 9bebbf3981251fec28220782c4b250c9fe8c5167aae0daa64d952f74fd6475a2

Contents?: true

Size: 645 Bytes

Versions: 16

Compression:

Stored size: 645 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.numerator, ratio.denominator);
};

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cqm-models-4.2.0 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.1.2 app/assets/javascripts/basetypes/Ratio.js
cqm-models-4.1.1 app/assets/javascripts/basetypes/Ratio.js
cqm-models-4.1.0 app/assets/javascripts/basetypes/Ratio.js
cqm-models-4.0.2 app/assets/javascripts/basetypes/Ratio.js
cqm-models-4.0.1 app/assets/javascripts/basetypes/Ratio.js
cqm-models-4.0.0 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.1.1 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.1.0 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.6 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.5 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.4 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.3 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.2 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.1 app/assets/javascripts/basetypes/Ratio.js
cqm-models-3.0.0 app/assets/javascripts/basetypes/Ratio.js