class License < ActiveRecord::Base belongs_to :company belongs_to :well_type belongs_to :location belongs_to :applicant, class_name: 'User', foreign_key: 'user_id' def status LicenseStatus.status_for(self) end def active_on?(date) issued_at < date && expired_at > date end def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page offset = offset >= 0 ? offset : 0 order(created_at: :desc).offset(offset).limit(per_page) end def self.township(township) joins(:location).where(locations: { township: township }) end def self.status(status) status.filter(self) end end