<commit_before>class NutritionIx
  include HTTParty

  attr_reader :search, :line_delimited

  ALLOWED_KEYS = [
    :food_name,
    :serving_qty,
    :serving_unit,
    :serving_weight_grams,
    :nf_calories,
    :nf_total_fat,
    :nf_saturated_fat,
    :nf_cholesterol,
    :nf_sodium,
    :nf_total_carbohydrate,
    :nf_dietary_fiber,
    :nf_sugars,
    :nf_protein,
    :nf_potassium,
    :ndb_no,
  ]

  base_uri "https://trackapi.nutritionix.com"

  def initialize(search = "", line_delimited = false)
    @search = search
    @line_delimited = line_delimited
  end

  def errors?
    data[:message] ? true : false
  end

  def messages
    data[:message] || "Your search was successful!"
  end

  def foods
    return [] if errors?

    @foods ||= parse_foods
  end

  def search=(search)
    @search = search
  end

  def line_delimited=(line_delimited)
    @line_delimited = line_delimited
  end

  def reload!
    @data = call_api
    @foods = nil
  end

  def data
    @data ||= call_api
  end

  private
  def parse_foods
    @foods = data[:foods].collect do |food|
      new_hash = {tag_id:  food[:tags][:tag_id]}
      new_hash = self.class.filter_keys(food, ALLOWED_KEYS)

      OpenStruct.new(new_hash)
    end
  end

  def call_api
    response = self.class.post(
      "/v2/natural/nutrients", headers: headers, body: body<commit_msg>Make data method private<commit_after>class NutritionIx
  include HTTParty

  attr_reader :search, :line_delimited

  ALLOWED_KEYS = [
    :food_name,
    :serving_qty,
    :serving_unit,
    :serving_weight_grams,
    :nf_calories,
    :nf_total_fat,
    :nf_saturated_fat,
    :nf_cholesterol,
    :nf_sodium,
    :nf_total_carbohydrate,
    :nf_dietary_fiber,
    :nf_sugars,
    :nf_protein,
    :nf_potassium,
    :ndb_no,
  ]

  base_uri "https://trackapi.nutritionix.com"

  def initialize(search = "", line_delimited = false)
    @search = search
    @line_delimited = line_delimited
  end

  def errors?
    data[:message] ? true : false
  end

  def messages
    data[:message] || "Your search was successful!"
  end

  def foods
    return [] if errors?

    @foods ||= parse_foods
  end

  def search=(search)
    @search = search
  end

  def line_delimited=(line_delimited)
    @line_delimited = line_delimited
  end

  def reload!
    @data = call_api
    @foods = nil
  end

  private
  def parse_foods
    @foods = data[:foods].collect do |food|
      new_hash = {tag_id:  food[:tags][:tag_id]}
      new_hash = self.class.filter_keys(food, ALLOWED_KEYS)

      OpenStruct.new(new_hash)
    end
  end

  def data
    @data ||= call_api
  end

  def call_api
    response = self.class.post(
      "/v2/natural/nutrients", headers: headers, body: body
{'fraction_non_alphanumeric': 0.10069827269386256, 'fraction_numerical': 0.000735023888276369, 'mean_word_length': 2.944927536231884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5687557', 'n_tokens_mistral': 1072, 'n_tokens_neox': 973, 'n_words': 208}