<commit_before>require "is_taggable"

class BlogEntry < ActiveRecord::Base
  is_taggable :tags
  before_save :create_permalink
  validates_presence_of :title

  default_scope order("created_at DESC")
  scope :published, lambda { where("blog_entries.created_at <= ?", Time.zone.now) }
  scope :latest, lambda { |n| published.limit(n) }

  has_many :images, :as => :viewable, :dependent => :destroy, :class_name => "BlogEntryImage"

  accepts_nested_attributes_for :images, :reject_if => lambda { |a| a[:attachment].blank? && a[:_destroy] != "1" }, :allow_destroy => true
 
  def self.by_date(date, period = nil)
    if date.is_a?(Hash)
      keys = [:day, :month, :year].select {|key| date.include?(key) }
      period = keys.first.to_s
      date = Date.new(*keys.reverse.map {|key| date[key].to_i })
    end

    time = date.to_time.in_time_zone
    find(:all, :conditions => {:created_at => (time.send("beginning_of_#{period}")..time.send("end_of_#{period}") )} )
  end 

  def self.by_tag(name)<commit_msg>mysql doesnt like single-quotes around arguments to LIMIT, so make sure its an int<commit_after>require "is_taggable"

class BlogEntry < ActiveRecord::Base
  is_taggable :tags
  before_save :create_permalink
  validates_presence_of :title

  default_scope order("created_at DESC")
  scope :published, lambda { where("blog_entries.created_at <= ?", Time.zone.now) }
  scope :latest, lambda { |n| published.limit(n.to_i) }

  has_many :images, :as => :viewable, :dependent => :destroy, :class_name => "BlogEntryImage"

  accepts_nested_attributes_for :images, :reject_if => lambda { |a| a[:attachment].blank? && a[:_destroy] != "1" }, :allow_destroy => true
 
  def self.by_date(date, period = nil)
    if date.is_a?(Hash)
      keys = [:day, :month, :year].select {|key| date.include?(key) }
      period = keys.first.to_s
      date = Date.new(*keys.reverse.map {|key| date[key].to_i })
    end

    time = date.to_time.in_time_zone
    find(:all, :conditions => {:created_at => (time.send("beginning_of_#{period}")..time.send("end_of_#{period}") )} )
  end 

  def self.by_tag(name)
{'fraction_non_alphanumeric': 0.15822179732313577, 'fraction_numerical': 0.0009560229445506692, 'mean_word_length': 4.479057591623037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '5290325', 'n_tokens_mistral': 749, 'n_tokens_neox': 741, 'n_words': 152}