<commit_before>require 'models'

class Array
  # https://codereview.stackexchange.com/questions/5863/ruby-function-to-join-array-with-commas-and-a-conjunction
  def to_sentence
    default_connector = ', '
    two_word_connector = ' and '
    last_word_connector = ', and '

    case size
      when 0
        ""
      when 1
        self[0].to_s.dup
      when 2
        "#{self[0]}#{two_word_connector}#{self[1]}"
      else
        "#{self[0...-1].join(default_connector)}#{last_word_connector}#{self[-1]}"
    end
  end
end

class Notifier
  def self.send_elevator_notifications!(elevators)
    # We want to notify all users whose station-list includes an elevator
    # affected by the latest run
    users = elevators.flat_map(&:users).uniq

    users.each do |user|
      # Get all the out elevators that currently affect this user
      my_elevators = Models::Outage.all_open(:elevator => user.elevators.to_a) # Mumble-mumble
                                   .to_a # Mumble-mumble datamapper::collection
                                   .map(&:elevator)
                                   .map(&:name)

      message = elevator_notification_message(my_elevators)

      puts "Sending an email to user #{user.id}..."
      Email.mail(:to => user.email,
                 :subject => "BART Elevator Alerts",
                 :body => message)
    end

    users
  end

  private

  # @param [Array<String>] elevators
  #
  # @return [String]
  def self.elevator_notification_message(elevators)
    raise ArgumentError unless elevators.is_a?(Array) && elevators.all? { |e| e.class == String }
    case elevators.size
    when 0
      "All of the elevators you subscribe to are currently in service."
    when 1
      "1 of the elevators you subscribe to is out of service: #{elevators.first}."
    else
      "#{elevators.size} of the elevators you subscribe to are out of service: #{elevators.to_sentence}."
    end
  end
end<commit_msg>Shorten language some<commit_after>require 'models'

class Array
  # https://codereview.stackexchange.com/questions/5863/ruby-function-to-join-array-with-commas-and-a-conjunction
  def to_sentence
    default_connector = ', '
    two_word_connector = ' and '
    last_word_connector = ', and '

    case size
      when 0
        ""
      when 1
        self[0].to_s.dup
      when 2
        "#{self[0]}#{two_word_connector}#{self[1]}"
      else
        "#{self[0...-1].join(default_connector)}#{last_word_connector}#{self[-1]}"
    end
  end
end

class Notifier
  def self.send_elevator_notifications!(elevators)
    # We want to notify all users whose station-list includes an elevator
    # affected by the latest run
    users = elevators.flat_map(&:users).uniq

    users.each do |user|
      # Get all the out elevators that currently affect this user
      my_elevators = Models::Outage.all_open(:elevator => user.elevators.to_a) # Mumble-mumble
                                   .to_a # Mumble-mumble datamapper::collection
                                   .map(&:elevator)
                                   .map(&:name)

      message = elevator_notification_message(my_elevators)

      puts "Sending an email to user #{user.id}..."
      Email.mail(:to => user.email,
                 :subject => "BART Elevator Alerts",
                 :body => message)
    end

    users
  end

  private

  # @param [Array<String>] elevators
  #
  # @return [String]
  def self.elevator_notification_message(elevators)
    raise ArgumentError unless elevators.is_a?(Array) && elevators.all? { |e| e.class == String }
    case elevators.size
    when 0
      "All of the elevators you subscribe to are currently in service."
    when 1
      "1 elevator you subscribe to is out: #{elevators.first}."
    else
      "#{elevators.size} elevators you subscribe to are out: #{elevators.to_sentence}."
    end
  end
end
{'fraction_non_alphanumeric': 0.10665286047113642, 'fraction_numerical': 0.008283717318146519, 'mean_word_length': 2.362924281984334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6288078', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1198, 'n_words': 297}