<commit_before>class Package < ActiveRecord::Base

	validates :ref_number, presence: true, uniqueness: true
	validates :description, presence: true
	validates :weight, presence: true, numericality: true
	validates :height, presence: true, numericality: true
	validates :depth, presence: true, numericality: true
	validates :width, presence: true, numericality: true
	validates :value, presence: true, numericality: true
	validates :shipping_cost, presence: true, numericality: true
	validates :status, presence: true, numericality: true
	validates :agency_id, presence: true, numericality: true
	validates :receiver_id, presence: true, numericality: true
	validates :sender_id, presence: true, numericality: true

	validates :status, inclusion: { in: 0..2 }

	belongs_to :receiver, class_name: "User", foreign_key: "receiver_id"
	belongs_to :sender, class_name: "User", foreign_key: "sender_id"
	belongs_to :agency

	default_scope {order(status: :asc)}
	scope :pending, -> { where(status: 0) }
	scope :arrived, -> { where(status: 1) }
	scope :delivered, -> { where(status: 2) }
	scope :agency_pending, -> { where.not(status: 2)}

	def status_human
		if status == 0
			I18n.t('pending')
		elsif status == 1
			I18n.t('arrived')
		else
			I18n.t('delivered')
		end	
	end

	def is_pending?
		if status == 0
			return true
		else
			return false
		end
	end

	def is_arrived?
		if status == 1
			return true
		else
			return false
		end
	end

	def is_delivered?
		if status == 2
			return true
		else
			return false
		end
	end

	# Search form by ref number<commit_msg>show sender, receiver info and status as text<commit_after>class Package < ActiveRecord::Base

	validates :ref_number, presence: true, uniqueness: true
	validates :description, presence: true
	validates :weight, presence: true, numericality: true
	validates :height, presence: true, numericality: true
	validates :depth, presence: true, numericality: true
	validates :width, presence: true, numericality: true
	validates :value, presence: true, numericality: true
	validates :shipping_cost, presence: true, numericality: true
	validates :status, presence: true, numericality: true
	validates :agency_id, presence: true, numericality: true
	validates :receiver_id, presence: true, numericality: true
	validates :sender_id, presence: true, numericality: true

	validates :status, inclusion: { in: 0..2 }

	belongs_to :receiver, class_name: "User", foreign_key: "receiver_id"
	belongs_to :sender, class_name: "User", foreign_key: "sender_id"
	belongs_to :agency

	default_scope {order(status: :asc)}
	scope :pending, -> { where(status: 0) }
	scope :arrived, -> { where(status: 1) }
	scope :delivered, -> { where(status: 2) }
	scope :agency_pending, -> { where.not(status: 2)}

	def status_human
		if status == 0
			'pending'
		elsif status == 1
			'arrived'
		else
			'delivered'
		end	
	end

	def is_pending?
		if status == 0
			return true
		else
			return false
		end
	end

	def is_arrived?
		if status == 1
			return true
		else
			return false
		end
	end

	def is_delivered?
		if status == 2
			return true
		else
			return false
		end
	end

	# Filter package attributes, show sender and receiver usernames, show status definition
	def as_json(options ={})
		hash_info = super({ except: [:sender_id, :receiver_id, :status] }.merge(options || {}))
		hash_info[:sender] = {id: sender.id, username: sender.username}
		hash_info[:receiver] = {id: receiver.id, username: receiver.username}
		hash_info[:status] = status_human
		hash_info
	end

	# Search form by ref number
{'fraction_non_alphanumeric': 0.10529295216529862, 'fraction_numerical': 0.007925275969431078, 'mean_word_length': 4.5046728971962615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7447320', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1151, 'n_words': 372}