<commit_before>class FruglesController < ApplicationController
  before_filter :authenticate_user!, :except => [:index, :verified, :show]
  after_filter :increase_views, :only => :print
  
  def index
    @frugles = Frugle.find :all, 
               :include => [:category, :subcategory, :business], 
               :conditions => ["LOWER(categories.title) LIKE ? OR LOWER(subcategories.title) LIKE ? OR LOWER(businesses.name) LIKE ? OR LOWER(cost) LIKE ?",
               "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%"]
    @frugles = @frugles | Frugle.tagged_with(params[:search])
  end

  def show
    @frugle = Frugle.find(params[:id])
    if user_signed_in?
      @save = Saved.find_by_user_id_and_frugle_id(current_user.id, @frugle.id)
    end
  end
  
  def print
    @frugle = Frugle.find(params[:id])
    render :layout => "print"
  end

  def new
    @frugle = Frugle.new
    @frugle_discount_options = [['% Off', 'percent'], ['$ Off', 'dollar'], ['$ For', 'flat'], ['Free with Purchase Of', 'bonus'], ['Buy One Get One Free', 'bogo']]
  end
  
  def update_cost
  end

  def create
    @frugle = current_user.business.frugles.new(params[:frugle])
    charset = %w{ 2 3 4 6 7 9 A C D E F G H J K L M N P Q R T V W X Y Z}
    @frugle.verification = (0...6).map{ charset.to_a[rand(charset.size)] }.join
    @frugle.status = "active"
    @frugle.views = 0
    @frugle.category_id = @frugle.business.category_id
    @frugle.subcategory_id = @frugle.business.subcategory_id
    @frugle.discount = params[:frugle][:discount]
    if @frugle.discount == "percent"
      @frugle.cost = [params[:frugle][:percentage], params[:frugle][:product]].join(" % Off ")
    elsif @frugle.discount == "dollar"
      @frugle.cost = ["$#{params[:frugle][:percentage]}", params[:frugle][:product]].join(" Off ")
    elsif @frugle.discount == "flat"
      @frugle.cost = "$#{params[:frugle][:percentage]} For #{params[:frugle][:product]}"
    elsif @frugle.discount == "bonus"
      @frugle.cost = "#{params[:frugle][:percentage]} With Purchase Of #{params[:frugle][:product]}"
    elsif @frugle.discount == "bogo"
      @frugle.cost = "Buy One #{params[:frugle][:percentage]} Get One #{params[:frugle][:product]} Free"
    end
    @frugle.tag_list = params[:frugle][:tag_list]
    if @frugle.save
      redirect_to root_path, :notice => "Successfully created frugle."
    else
      render :action => 'new'
    end
  end

  def edit
    @frugle = Frugle.find(params[:id])
    @frugle_discount_options = {'% Off' => 'percent', '$ Off' => 'dollar', '$ For' => 'flat', 'Free with Purchase Of' => 'bonus', 'Buy One Get One Free' => 'bogo' }
  end
  
  def verified
    @frugle = Frugle.find_by_verification(params[:search])<commit_msg>update seed and some other thingers<commit_after>class FruglesController < ApplicationController
  before_filter :authenticate_user!, :except => [:index, :verified, :show]
  after_filter :increase_views, :only => :print
  
  def index
    @frugles = Frugle.find :all, 
               :include => [:category, :subcategory, :business], 
               :conditions => ["LOWER(categories.title) LIKE ? OR LOWER(subcategories.title) LIKE ? OR LOWER(businesses.name) LIKE ? OR LOWER(cost) LIKE ?",
               "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%", "%#{params[:search].to_s.downcase}%"]
    @frugles = @frugles | Frugle.tagged_with(params[:search])
  end

  def show
    @frugle = Frugle.find(params[:id])
    if user_signed_in?
      @save = Saved.find_by_user_id_and_frugle_id(current_user.id, @frugle.id)
    end
  end
  
  def print
    @frugle = Frugle.find(params[:id])
    render :layout => "print"
  end

  def new
    @frugle = Frugle.new
    @frugle_discount_options = [['% Off', 'percent'], ['$ Off', 'dollar'], ['$ For', 'flat'], ['Free with Purchase Of', 'bonus'], ['Buy One Get One Free', 'bogo']]
  end
  
  def update_cost
  end

  def create
    @frugle = current_user.business.frugles.new(params[:frugle])
    charset = %w{ 2 3 4 6 7 9 A C D E F G H J K L M N P Q R T V W X Y Z}
    @frugle.verification = (0...6).map{ charset.to_a[rand(charset.size)] }.join
    @frugle.status = "active"
    @frugle.views = 0
    @frugle.category_id = @frugle.business.category_id
    @frugle.subcategory_id = @frugle.business.subcategory_id
    @frugle.discount = params[:frugle][:discount]
    if @frugle.discount == "percent"
      @frugle.cost = [params[:frugle][:percentage], params[:frugle][:product]].join(" % Off ")
    elsif @frugle.discount == "dollar"
      @frugle.cost = ["$#{params[:frugle][:percentage]}", params[:frugle][:product]].join(" Off ")
    elsif @frugle.discount == "flat"
      @frugle.cost = "$#{params[:frugle][:percentage]} For #{params[:frugle][:product]}"
    elsif @frugle.discount == "bonus"
      @frugle.cost = "Free #{params[:frugle][:percentage]} With Purchase Of #{params[:frugle][:product]}"
    elsif @frugle.discount == "bogo"
      @frugle.cost = "Buy One #{params[:frugle][:percentage]} Get One #{params[:frugle][:product]} Free"
    end
    @frugle.tag_list = params[:frugle][:tag_list]
    if @frugle.save
      redirect_to root_path, :notice => "Successfully created frugle."
    else
      render :action => 'new'
    end
  end

  def edit
    @frugle = Frugle.find(params[:id])
    @frugle_discount_options = {'% Off' => 'percent', '$ Off' => 'dollar', '$ For' => 'flat', 'Free with Purchase Of' => 'bonus', 'Buy One Get One Free' => 'bogo' }
  end
  
  def verified
    @frugle = Frugle.find_by_verification(params[:search])
{'fraction_non_alphanumeric': 0.17527772879562686, 'fraction_numerical': 0.0031740433785928408, 'mean_word_length': 3.730608840700584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1542413', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2093, 'n_words': 443}