<commit_before>import { autobind }  from 'core-decorators';

const isInteger = function (num) {
  return typeof num === 'number' && num % 1 === 0;
}

const isWord = function (str) {
  return typeof str === 'string' && str.length > 0;
}

const isEmpty = function (str) {
  return typeof str !== 'string' || str.length === 0 || str === 'なし' || str === '無';
}

export default class Character {
  constructor () {
    this.no = 0;
    this.name = { jp: null, tw: null };
    this.imgUrl = 'http://onepiece-treasurecruise.com/wp-content/themes/onepiece-treasurecruise/images/noimage.png';
    this.type = null;
    this.classes = [];
    this.star = 0;
    this.cost = 0;
    this.combo = 1;
    this.min = { lv: 0, hp: 0, atk: 0, rcv: 0 };
    this.max = { lv: 0, hp: 0, atk: 0, rcv: 0 };
    this.specialAbility = {
      jp: { name: null, content: null },
      tw: { name: null, content: null }
    };
    this.captainEffect = {
      jp: { name: null, content: null },
      tw: { name: null, content: null }
    };
  }

  @autobind
  setNo (no) {
    if (!isInteger(no) || no < 1) {
      throw new Error('Invalid parameter: no = ' + no);
    }

    this.no = no;
    return this;
  }
<commit_msg>[lib] implement static methods Character.compact() and Character.parse()<commit_after>import { autobind }  from 'core-decorators';

const isInteger = function (num) {
  return typeof num === 'number' && num % 1 === 0;
}

const isWord = function (str) {
  return typeof str === 'string' && str.length > 0;
}

const isEmpty = function (str) {
  return typeof str !== 'string' || str.length === 0 || str === 'なし' || str === '無';
}

export default class Character {
  static compact (character) {
    const c = character;
    return [
      c.no,                   // 0
      [c.name.jp, c.name.tw], // 1
      c.imgUrl,               // 2
      c.type,                 // 3
      c.classes,              // 4
      c.star,                 // 5
      c.cost,                 // 6
      c.combo,                // 7
      [c.min.lv, c.min.hp, c.min.atk, c.min.rcv], // 8
      [c.max.lv, c.max.hp, c.max.atk, c.max.rcv], // 9
      [
        [c.specialAbility.jp.name, c.specialAbility.jp.content],
        [c.specialAbility.tw.name, c.specialAbility.tw.content]
      ],
      [
        [c.captainEffect.jp.name, c.captainEffect.jp.content],
        [c.captainEffect.tw.name, c.captainEffect.tw.content]
      ]
    ];
  }

  static parse (data) {
    if (Array.isArray(data) === false) {
      return null;
    }

    const c = new Character();
    c.no = data[0];
    c.name = {
      jp: data[1][0],
      tw: data[1][1]
    };
    c.imgUrl  = data[2];
    c.type    = data[3];
    c.classes = data[4];
    c.star    = data[5];
    c.cost    = data[6];
    c.combo   = data[7];
    c.min = {
      lv:  data[8][0],
      hp:  data[8][1],
      atk: data[8][2],
      rcv: data[8][3]
    };
    c.max = {
      lv:  data[9][0],
      hp:  data[9][1],
      atk: data[9][2],
      rcv: data[9][3]
    };
    c.specialAbility = {
      jp: { name: data[10][0][0], content: data[10][0][1] },
      tw: { name: data[10][1][0], content: data[10][1][1] }
    };
    c.captainEffect = {
      jp: { name: data[11][0][0], content: data[11][0][1] },
      tw: { name: data[11][1][0], content: data[11][1][1] }
    };
    return c;
  }

  constructor () {
    this.no = 0;
    this.name = { jp: null, tw: null };
    this.imgUrl = 'http://onepiece-treasurecruise.com/wp-content/themes/onepiece-treasurecruise/images/noimage.png';
    this.type = null;
    this.classes = [];
    this.star = 0;
    this.cost = 0;
    this.combo = 1;
    this.min = { lv: 0, hp: 0, atk: 0, rcv: 0 };
    this.max = { lv: 0, hp: 0, atk: 0, rcv: 0 };
    this.specialAbility = {
      jp: { name: null, content: null },
      tw: { name: null, content: null }
    };
    this.captainEffect = {
      jp: { name: null, content: null },
      tw: { name: null, content: null }
    };
  }

  @autobind
  setNo (no) {
    if (!isInteger(no) || no < 1) {
      throw new Error('Invalid parameter: no = ' + no);
    }

    this.no = no;
    return this;
  }

{'fraction_non_alphanumeric': 0.1847984458474988, 'fraction_numerical': 0.025012141816415735, 'mean_word_length': 1.9761560693641618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '771469', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1546, 'n_words': 359}