<commit_before>class RecipeParser

  def initialize(page)
    @page = agent.get(page)
    @directions = []
    @ingredients = []
    get_ingredients
    get_directions
  end

  def agent
    Mechanize.new
  end

  def name
    @page.search(name_id).inner_text
  end

  def name_id
    "#itemTitle"
  end

  def image
    @page.search(image_id).first.attributes["src"].value
  end

  def image_id
    "#imgPhoto"
  end

  def servings
    @page.search(servings_id).inner_text.gsub(" servings", "").to_i
  end

  def servings_id
    "#lblYield"
  end

  def directions_class
    ".directions ol li span"
  end

  def directions_list
    @page.search(directions_class)
  end

  def get_directions
    directions_list.each do |direction|
      @directions << direction.text
    end
  end

  def ingredients_list
    page.search(ingredients_class)
  end

  def ingredients_class
    ".fl-ing"
  end

  def get_ingredients
    ingredients_list.each do |ingredient|
      amount = amount(ingredient)
      ingredient_name= ingredient_name(ingredient)
      add_ingredient_to_list(amount, ingredient_name)
    end
  end

  def add_ingredient_to_list(amount, ingredient_name)
    if amount && ingredient_name #some recipes have empty ingredients
      quantity,unit = amount.text.split(" ")
      @ingredients << { "quantity" => quantity.to_f, "unit"=>unit, "name" => ingredient_name.text }
    end
  end

  def amount
    ingredient.search(ingredient_amount_class).children[0]
  end

  def ingredient_amount_class
    ".ingredient-amount"
  end

  def ingredient_name
    ingredient.search(ingredient_name_class).children[0]
  end

  def ingredient_name_class
    ".ingredient-name"
  end

  def recipe
    {
      name: name,
      image: image,
      servings: servings,
      ingredients: @ingredients,
      directions: @directions
    }
  end

end
<commit_msg>Use absolute URL when fetching recipes<commit_after>class RecipeParser
  $BASE_URL = "http://allrecipes.com"

  def initialize(page)
    @page = agent.get $BASE_URL + page
    @directions = []
    @ingredients = []
    get_ingredients
    get_directions
  end

  def agent
    Mechanize.new
  end

  def name
    @page.search(name_id).inner_text
  end

  def name_id
    "#itemTitle"
  end

  def image
    @page.search(image_id).first.attributes["src"].value
  end

  def image_id
    "#imgPhoto"
  end

  def servings
    @page.search(servings_id).inner_text.gsub(" servings", "").to_i
  end

  def servings_id
    "#lblYield"
  end

  def directions_class
    ".directions ol li span"
  end

  def directions_list
    @page.search(directions_class)
  end

  def get_directions
    directions_list.each do |direction|
      @directions << direction.text
    end
  end

  def ingredients_list
    page.search(ingredients_class)
  end

  def ingredients_class
    ".fl-ing"
  end

  def get_ingredients
    ingredients_list.each do |ingredient|
      amount = amount(ingredient)
      ingredient_name= ingredient_name(ingredient)
      add_ingredient_to_list(amount, ingredient_name)
    end
  end

  def add_ingredient_to_list(amount, ingredient_name)
    if amount && ingredient_name #some recipes have empty ingredients
      quantity,unit = amount.text.split(" ")
      @ingredients << { "quantity" => quantity.to_f, "unit"=>unit, "name" => ingredient_name.text }
    end
  end

  def amount
    ingredient.search(ingredient_amount_class).children[0]
  end

  def ingredient_amount_class
    ".ingredient-amount"
  end

  def ingredient_name
    ingredient.search(ingredient_name_class).children[0]
  end

  def ingredient_name_class
    ".ingredient-name"
  end

  def recipe
    {
      name: name,
      image: image,
      servings: servings,
      ingredients: @ingredients,
      directions: @directions
    }
  end

end

{'fraction_non_alphanumeric': 0.08606124604012672, 'fraction_numerical': 0.0010559662090813093, 'mean_word_length': 3.0351437699680512, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '2739381', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1265, 'n_words': 275}