<commit_before>require 'date'
require 'informal'

class StaffCalendarEnquiry
  include Informal::Model
  
  attr_reader :account
  validates_presence_of :account

  attr_reader :employee
  validates_presence_of :employee
  
  attr_accessor :date_from
  validates :date_from, :timeliness => { :type => :date }
  
  attr_accessor :date_to
  validates :date_to, :timeliness => { :type => :date }
  
  attr_accessor :filter_by
  validates :filter_by, :inclusion => { :in => %w{none location department employee} }
  
  attr_accessor :item_id

  validate :date_from_must_occur_before_date_to, 
           :date_to_must_occur_after_date_from,
           :duration_at_least_one_month

  def initialize(account, employee)
    @account = account
    @employee = employee
    @filter_by = 'none'
    @leave_requests_by_employee = {}
  end

  def date_range
    (self.date_from..self.date_to)
  end
  
  def employees
    self.employee.staff
  end
  
  def leave_requests_for(employee)
    @leave_requests_by_employee[employee] ||= employee
      .leave_requests
      .active
      .where(
        ' date_from BETWEEN :date_from AND :date_to OR date_to BETWEEN :date_from AND :date_to ',
        { :date_from => self.date_from, :date_to => self.date_to }
      )
  end

  # TODO: implement enquiry here!!!
  #  refactor view to use this class instead  <commit_msg>fix to calendar enquiry helper class<commit_after>require 'date'
require 'informal'

class StaffCalendarEnquiry
  include Informal::Model
  
  attr_reader :account
  validates_presence_of :account

  attr_reader :employee
  validates_presence_of :employee
  
  attr_accessor :date_from
  validates :date_from, :timeliness => { :type => :date }
  
  attr_accessor :date_to
  validates :date_to, :timeliness => { :type => :date }
  
  attr_accessor :filter_by
  validates :filter_by, :inclusion => { :in => %w{none location department employee} }
  
  attr_accessor :item_id

  validate :date_from_must_occur_before_date_to, 
           :date_to_must_occur_after_date_from,
           :duration_at_least_one_month

  def initialize(account, employee)
    @account = account
    @employee = employee
    @filter_by = 'none'
    @leave_requests_by_employee = {}
  end

  def date_range
    (self.date_from..self.date_to)
  end
  
  def employees
    self.employee.staff
  end
  
  def leave_requests_for(employee)
    @leave_requests_by_employee[employee] ||= employee
      .leave_requests
      .active
      .where(
        ' date_from BETWEEN :date_from AND :date_to OR date_to BETWEEN :date_from AND :date_to ',
        { :date_from => self.date_from, :date_to => self.date_to }
      )
      .order(:date_from)
  end

  # TODO: implement enquiry here!!!
  #  refactor view to use this class instead  
{'fraction_non_alphanumeric': 0.08635703918722787, 'fraction_numerical': 0.0, 'mean_word_length': 3.446774193548387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7562782', 'n_tokens_mistral': 962, 'n_tokens_neox': 919, 'n_words': 204}