Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 8x 1x 1x 1x 340x 1x 339x 1x 337x 1x 11x 11x 5x 1x | I{ Exception } = require '../datatypes/exception' { Expression } = require './expression' { Quantity } = require('./quantity') module.exports.Ratio = class Ratio extends Expression constructor: (json) -> super if !json.numerator? throw new Error("Cannot create a ratio with an undefined numerator value") else @numerator = new Quantity(json.numerator) if !json.denominator? throw new Error("Cannot create a ratio with an undefined denominator value") else @denominator = new Quantity(json.denominator) # Define a simple getter to allow type-checking of this class without instanceof # and in a way that survives minification (as opposed to checking constructor.name) Object.defineProperties @prototype, isRatio: get: -> true clone: () -> new Ratio({numerator: @numerator.clone(), denominator: @denominator.clone()}) exec: (ctx) -> @ toString: () -> "#{@numerator.toString()} : #{@denominator.toString()}" equals: (other) -> if other instanceof Ratio divided_this = @numerator.dividedBy(@denominator) divided_other = other.numerator.dividedBy(other.denominator) divided_this.equals(divided_other) else false equivalent: (other) -> equal = @equals(other) if !equal? return false equal module.exports.createRatio = createRatio = (numerator, denominator) -> new Ratio({numerator: numerator, denominator: denominator}) |