<commit_before>'use strict';

var _ = require('lodash');

var Element = require('./element');
var ArrayElement = require('./array-element');
var MemberElement = require('./member-element');
var ObjectSlice = require('../object-slice');

/**
 * @class
 *
 * @param content
 * @param meta
 * @param attributes
 *
 * @extends ArrayElement
 */
var ObjectElement = ArrayElement.extend({
  constructor: function (content, meta, attributes) {
    var convertedContent = _.keys(content).map(function(key) {
      return new MemberElement(key, content[key]);
    });
    Element.call(this, convertedContent, meta, attributes);
    this.element = 'object';
  },

  primitive: function() {
    return 'object';
  },

  toValue: function() {
    return this.content.reduce(function(results, el) {
      results[el.key.toValue()] = el.value.toValue();
      return results;
    }, {});
  },

  /**
   * @returns {Element}
   * @memberof ObjectElement.prototype
   */
  get: function(name) {
    if (name === undefined) { return undefined; }

    var member = _.first(
      this.content.filter(function(item) {
        return item.key.toValue() === name;
      })
    ) || {};

    return member.value;
  },

  /**
   * @returns {MemberElement}
   * @memberof ObjectElement.prototype
   */
  getMember: function(name) {
    if (name === undefined) { return undefined; }

    return _.first(
      this.content.filter(function(item) {
        return item.key.toValue() === name;
      })
    );
  },

  /**
   * @memberof ObjectElement.prototype
   */
  remove: function (name) {
    var removed = null;

    this.content = this.content.filter(function (item) {
      if (item.key.toValue() === name) {
        removed = item;
        return false;
      }

      return true;
    });

    return removed;
  },

  /**
   * @returns {Element}
   * @memberof ObjectElement.prototype
   */
  getKey: function(name) {
    var member = this.getMember(name);
<commit_msg>refactor(ObjectElement): Simplify getMember implementation<commit_after>'use strict';

var _ = require('lodash');

var Element = require('./element');
var ArrayElement = require('./array-element');
var MemberElement = require('./member-element');
var ObjectSlice = require('../object-slice');

/**
 * @class
 *
 * @param content
 * @param meta
 * @param attributes
 *
 * @extends ArrayElement
 */
var ObjectElement = ArrayElement.extend({
  constructor: function (content, meta, attributes) {
    var convertedContent = _.keys(content).map(function(key) {
      return new MemberElement(key, content[key]);
    });
    Element.call(this, convertedContent, meta, attributes);
    this.element = 'object';
  },

  primitive: function() {
    return 'object';
  },

  toValue: function() {
    return this.content.reduce(function(results, el) {
      results[el.key.toValue()] = el.value.toValue();
      return results;
    }, {});
  },

  /**
   * @returns {Element}
   * @memberof ObjectElement.prototype
   */
  get: function(name) {
    var member = this.getMember(name);

    if (member) {
      return member.value;
    }

    return undefined;
  },

  /**
   * @returns {MemberElement}
   * @memberof ObjectElement.prototype
   */
  getMember: function(name) {
    if (name === undefined) { return undefined; }

    return this.content.find(function (element) {
      return element.key.toValue() === name;
    });
  },

  /**
   * @memberof ObjectElement.prototype
   */
  remove: function (name) {
    var removed = null;

    this.content = this.content.filter(function (item) {
      if (item.key.toValue() === name) {
        removed = item;
        return false;
      }

      return true;
    });

    return removed;
  },

  /**
   * @returns {Element}
   * @memberof ObjectElement.prototype
   */
  getKey: function(name) {
    var member = this.getMember(name);

{'fraction_non_alphanumeric': 0.15643771219639593, 'fraction_numerical': 0.0, 'mean_word_length': 2.8608870967741935, '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': '906034', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1146, 'n_words': 252}