<commit_before>import Cast from './Cast';
import Valid from './Valid';

export default class Attribute {

  static fromXMLObject(obj) {
    var defaultValue = undefined;

    if (obj.$['default'] !== undefined) {
      defaultValue = Cast.value(obj.$['default'], obj.$.type);
    }

    var attr = new Attribute(obj.$.name,
      obj.$.type,
      (obj.$['primary-key'] === 'true'),
      (obj.$['unique'] === 'true'),
      (obj.$['nullable'] === 'true'),
      defaultValue
    );

    attr.defaultValueIsFunction = ((obj.$['default'] !== undefined) && obj.$['default'].match(/^.*\(\)$/) !== null);
    if (obj.$['doc'] !== undefined)
      attr.doc = obj.$['doc'];
    if (obj.$['exact-length'] !== undefined)
      attr.exactLength = Cast.integer(obj.$['exact-length']);
    else {
      if (obj.$['max-length'] !== undefined)
        attr.maxLength = Cast.integer(obj.$['max-length']);
      if (obj.$['min-length'] !== undefined)
        attr.minLength = Cast.integer(obj.$['min-length']);
    }
    if (obj.$['genre'] !== undefined)
      attr.genre = obj.$['genre'];
    attr.regex = obj.$.regex;

    var matches;
    if ((matches = attr.type.match(/Decimal\(([0-9]+),([0-9]+)\)/))) {
      attr.precision = Number(matches[1]);
      attr.scale = Number(matches[2]);
      attr.type = 'Decimal';
    }<commit_msg>Attribute: if genre specifed, tries to guess from name<commit_after>import Cast from './Cast';
import Valid from './Valid';

export default class Attribute {

  static fromXMLObject(obj) {
    var defaultValue = undefined;

    if (obj.$['default'] !== undefined) {
      defaultValue = Cast.value(obj.$['default'], obj.$.type);
    }

    var attr = new Attribute(obj.$.name,
      obj.$.type,
      (obj.$['primary-key'] === 'true'),
      (obj.$['unique'] === 'true'),
      (obj.$['nullable'] === 'true'),
      defaultValue
    );

    attr.defaultValueIsFunction = ((obj.$['default'] !== undefined) && obj.$['default'].match(/^.*\(\)$/) !== null);
    if (obj.$['doc'] !== undefined)
      attr.doc = obj.$['doc'];
    if (obj.$['exact-length'] !== undefined)
      attr.exactLength = Cast.integer(obj.$['exact-length']);
    else {
      if (obj.$['max-length'] !== undefined)
        attr.maxLength = Cast.integer(obj.$['max-length']);
      if (obj.$['min-length'] !== undefined)
        attr.minLength = Cast.integer(obj.$['min-length']);
    }
    if (obj.$['genre'] !== undefined)
      attr.genre = obj.$['genre'];
    else if (Valid.genre(attr.name)) // If attribute's name is a genre
      attr.genre = attr.name;
    attr.regex = obj.$.regex;

    var matches;
    if ((matches = attr.type.match(/Decimal\(([0-9]+),([0-9]+)\)/))) {
      attr.precision = Number(matches[1]);
      attr.scale = Number(matches[2]);
      attr.type = 'Decimal';
    }
{'fraction_non_alphanumeric': 0.23151471643933955, 'fraction_numerical': 0.004307250538406317, 'mean_word_length': 2.8282967032967035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '459888', 'n_tokens_mistral': 895, 'n_tokens_neox': 876, 'n_words': 177}