<commit_before># frozen_string_literal: true

require_dependency "gobierto_people"

module GobiertoPeople
  class Trip < ApplicationRecord

    include GobiertoCommon::Metadatable
    include GobiertoCommon::UrlBuildable

    belongs_to :person
    belongs_to :department

    scope :sorted, -> { order(start_date: :desc) }

    validates :person, :title, :start_date, :end_date, presence: true

    metadata_attributes(
      :food_expenses,
      :accomodation_expenses,
      :transport_expenses,
      :other_expenses,
      :total_expenses,
      :company,
      :comments,
      :original_destinations_attribute,
      :purpose
    )

    def destinations
      destinations_meta["destinations"] if destinations_meta
    end

    def duration_dates
      [start_date, end_date]
    end

    def parameterize
      { person_slug: person.slug, id: id }
    end<commit_msg>Add between_dates scope to GobiertoPeople::Trip<commit_after># frozen_string_literal: true

require_dependency "gobierto_people"

module GobiertoPeople
  class Trip < ApplicationRecord

    include GobiertoCommon::Metadatable
    include GobiertoCommon::UrlBuildable

    belongs_to :person
    belongs_to :department

    scope :sorted, -> { order(start_date: :desc) }
    scope :between_dates, lambda { |start_date, end_date|
      if start_date && end_date
        where("start_date >= ? AND end_date <= ?", start_date, end_date)
      elsif start_date
        where("start_date >= ?", start_date)
      elsif end_date
        where("end_date <= ?", end_date)
      end
    }

    validates :person, :title, :start_date, :end_date, presence: true

    metadata_attributes(
      :food_expenses,
      :accomodation_expenses,
      :transport_expenses,
      :other_expenses,
      :total_expenses,
      :company,
      :comments,
      :original_destinations_attribute,
      :purpose
    )

    def destinations
      destinations_meta["destinations"] if destinations_meta
    end

    def duration_dates
      [start_date, end_date]
    end

    def parameterize
      { person_slug: person.slug, id: id }
    end
{'fraction_non_alphanumeric': 0.08066825775656325, 'fraction_numerical': 0.0, 'mean_word_length': 3.1587301587301586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '107879', 'n_tokens_mistral': 664, 'n_tokens_neox': 643, 'n_words': 139}