class List < ApplicationRecord
	has_many :items, dependent: :destroy
	belongs_to :user
	validates_presence_of :user_id, :list_name
	validates_length_of :list_name, in: 2..40

	def sort_blacklisted
		self.items.select { |item| item.blacklisted == true }
	end

	def sort_purchased
		self.items.select { |item| item.purchaser_id }
	end

	def sort_newest
		self.items.sort { |a,b| b.created_at <=> a.created_at }
	end

	def sort_oldest
		self.items.sort { |a,b| a.created_at <=> b.created_at }
	end

	def sort_updated
		self.items.sort { |a,b| b.updated_at <=> a.updated_at }
	end
end