Code coverage report for code/models/link.coffee

Statements: 75% (21 / 28)      Branches: 100% (2 / 2)      Functions: 62.5% (5 / 8)      Lines: 84.21% (16 / 19)      Ignored: none     

All files » code/models/ » link.coffee
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 491 1 1   1 1       85 85   85       85 85         85 44   41 85     3                       5              
GraphPrimitive = require './graph-primitive'
Relation = require "./relationship"
module.exports = class Link extends GraphPrimitive
 
  @defaultColor = "#777"
  @defaultRelation = new Relation
    formula: "1 * in"
 
  constructor: (@options={}) ->
    @options.color ?= Link.defaultColor
    @options.title ?= ''
 
    {
      @sourceNode, @sourceTerminal, @targetNode, @targetTerminal,
      @color, @title
    } = @options
    @relation = @_makeRelation @options.relation
    super()
 
  type: 'Link'
 
  _makeRelation: (relationObj) ->
    unless (relationObj instanceof Relation)
      relation = new Relation (relationObj or {})
    else
      relation = relationObj
    return relation
 
  terminalKey: ->
    "#{@sourceNode.key} ------> #{@targetNode.key}"
 
  nodeKey: ->
    "#{@sourceNode} ---#{@key}---> #{@targetNode}"
 
  outs: ->
    [@targetNode]
 
  ins: ->
    [@sourceNode]
 
  toExport: ->
    "title": @title
    "color": @color
    "sourceNode": @sourceNode.key
    "sourceTerminal": @sourceTerminal
    "targetNode": @targetNode.key
    "targetTerminal": @targetTerminal
    "relation": @relation.toExport()