<commit_before>class Book < ActiveRecord::Base
  attr_accessible :ISBN, :UUID, :publish_date, :title, :subtitle
  has_many :reservation
  has_and_belongs_to_many :author
  has_one :google_book_data

  searchable do
    text :title, :ISBN, :author
  end

  def as_json(options = {})
    json = super(options)
    json[:authors] = self.author.as_json(only: [:first_name, :last_name, :middle_initial])
    json[:thumbnail] = self.google_book_data.img_thumbnail

    json
  end
  

  def checked_out?
    checkouts = Checkout.where(checked_in_at: nil).select do |i|
      i.book.id == self.id
    end

    checkouts.any?
  end


  def reserved?
    Reservation.where(book_id: self.id, fuffiled: false).any?
  end

  def self.featured_book
    all = Book.includes(:google_book_data).where("google_book_data.description IS NOT ''")
    index = (rand(0..(all.count-1)))
    all[index]
  end



end
<commit_msg>Updates books to not use raw sql<commit_after>class Book < ActiveRecord::Base
  attr_accessible :ISBN, :UUID, :publish_date, :title, :subtitle
  has_many :reservation
  has_and_belongs_to_many :author
  has_one :google_book_data

  searchable do
    text :title, :ISBN, :author
  end

  def as_json(options = {})
    json = super(options)
    json[:authors] = self.author.as_json(only: [:first_name, :last_name, :middle_initial])
    json[:thumbnail] = self.google_book_data.img_thumbnail

    json
  end
  

  def checked_out?
    checkouts = Checkout.where(checked_in_at: nil).select do |i|
      i.book.id == self.id
    end

    checkouts.any?
  end


  def reserved?
    Reservation.where(book_id: self.id, fuffiled: false).any?
  end

  def self.featured_book
    gb = GoogleBookData.arel_table
    all = GoogleBookData.where(gb[:description].not_eq(""))
    index = (rand(0..(all.count-1)))
    all[index].book
  end



end

{'fraction_non_alphanumeric': 0.11668484187568157, 'fraction_numerical': 0.0021810250817884407, 'mean_word_length': 3.6105527638190953, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6372420', 'n_tokens_mistral': 677, 'n_tokens_neox': 651, 'n_words': 136}