import { Pipe , PipeTransform } from '@angular/core' ; import { Segment } from './segment' ; @ Pipe ( { name : 'createSegments' } ) export class CreateSegmentsPipe implements PipeTransform { param product return transform ( product ) { if ( ! product || ! product . properties ) { return null ; } let segments = [ ] ; const properties = product . properties ; for ( let i = 1 ; ; i ++ ) { const segment = this . _parseSegment ( properties , i ) ; if ( ! segment ) { break ; } segments . push ( segment ) ; } if ( segments . length < 2 ) { segments = null ; } return segments ; } private _parseSegment ( properties , id ) { const dipProp = `segment-${ id }-dip` , strikeProp = `segment-${ id }-strike` ; if ( properties . hasOwnProperty ( dipProp ) && properties . hasOwnProperty ( strikeProp ) ) { return { dip : properties [ dipProp ] , id : id , strike : properties [ strikeProp ] } ; } else { return null ; } } }