All files / answers-chart/Answers index.js

44.44% Statements 8/18
66.67% Branches 8/12
25% Functions 2/8
44.44% Lines 8/18
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71            1x                                                                   5x 5x 2x 3x 2x   1x   5x                                            
/*
  eslint-disable class-methods-use-this
*/
 
export class Answer {
  getTitle(value) {
    return `${value.charAt(0).toUpperCase()}${value.slice(1).toLowerCase()}`.replace(/_\w+$/, '');
  }
 
  getDescription() {
    return 'posts earn the highest engagement';
  }
 
  getChartLabel(value) {
    return this.getTitle(value);
  }
}
 
export class DayAnswer extends Answer {
 
  getChartLabel(value) {
    return value.charAt(0).toUpperCase();
  }
}
 
export class FrequencyAnswer {
  TIMES = { // eslint-disable-line no-undef
    1: 'Once',
    2: 'Twice',
    3: 'Three',
    4: 'Four',
    5: 'Five',
    6: 'Six',
    7: 'Seven',
    8: 'Eight',
    9: 'Nine',
  };
 
  getTitle(value) {
    let times;
    value = Number(value);
    if (value === 1 || value === 2) {
      times = this.TIMES[value];
    } else if (value > 2 && value < 10) {
      times = `${this.TIMES[value]} times`;
    } else {
      times = `${value} times`;
    }
    return `${times} daily`;
  }
 
  getDescription() {
    return 'is your most effective posting frequency';
  }
 
  getChartLabel(value) {
    return this.getTitle(value);
  }
}
 
export default class Answers {
  static forType(metricType) {
    if (metricType === 'frequency') {
      return new FrequencyAnswer();
    } else if (metricType === 'day') {
      return new DayAnswer();
    }
    return new Answer();
  }
}