All files NativeApplicationDescriptor.js

100% Statements 17/17
100% Branches 14/14
100% Functions 8/8
100% Lines 17/17
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 49 50 51 52 53 54                      38x 2x   36x 2x   34x 34x 34x       8x       6x       4x       4x       6x       12x       6x 6x 6x 3x      
// @flow
 
export default class NativeApplicationDescriptor {
  _name: string
  _platform: ?string
  _version: ?string
 
  constructor (
    name: string,
    platform: ?string,
    version: ?string) {
    if (!name) {
      throw new Error('[NativeApplicationDescriptor] name is required')
    }
    if (!platform && version) {
      throw new Error('[NativeApplicationDescriptor] platform is required when providing version')
    }
    this._name = name
    this._platform = platform
    this._version = version
  }
 
  get name () : string {
    return this._name
  }
 
  get platform () : ?string {
    return this._platform
  }
 
  get version () : ?string {
    return this._version
  }
 
  get isComplete () : boolean {
    return (this._platform !== undefined) && (this._version !== undefined)
  }
 
  get isPartial () : boolean {
    return (this._platform === undefined) || (this._version === undefined)
  }
 
  static fromString (napDescriptorLiteral: string) : NativeApplicationDescriptor {
    return new NativeApplicationDescriptor(...napDescriptorLiteral.split(':'))
  }
 
  toString () : string {
    let str = this._name
    str += this._platform ? `:${this._platform}` : ''
    str += this._version ? `:${this._version}` : ''
    return str
  }
}