<commit_before>class DashboardController < ApplicationController
  authorize_resource :class => false

  def index
    @rides = current_user.rides.latest.first(16)
    @ride = build_ride
  end

  private

  def build_ride
    if current_user.rides.any?
      last_ride = current_user.rides.latest.first
      attrs = last_ride.attributes.slice(*copyable_ride_attrs)
    else
      attrs = {}
    end
    Ride.new(default_ride_attrs.merge(attrs).symbolize_keys)
  end

  def copyable_ride_attrs
    %w{bike_distance bus_distance walk_distance description is_round_trip work_trip}
  end

  def default_ride_attrs
    { date: Calendar.today, is_round_trip: true, work_trip: true }
  end
end<commit_msg>Auto populate ride form with last work trip<commit_after>class DashboardController < ApplicationController
  authorize_resource :class => false

  def index
    @rides = current_user.rides.latest.first(16)
    @ride = build_ride
  end

  private

  def build_ride
    last_ride = current_user.rides.where(work_trip: true).latest.first
    if last_ride.present?
      attrs = last_ride.attributes.slice(*copyable_ride_attrs)
    else
      attrs = {}
    end
    Ride.new(default_ride_attrs.merge(attrs).symbolize_keys)
  end

  def copyable_ride_attrs
    %w{bike_distance bus_distance walk_distance description is_round_trip work_trip}
  end

  def default_ride_attrs
    { date: Calendar.today, is_round_trip: true }
  end
end
{'fraction_non_alphanumeric': 0.07077785564120533, 'fraction_numerical': 0.002803083391730904, 'mean_word_length': 3.8737201365187715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4214445', 'n_tokens_mistral': 473, 'n_tokens_neox': 454, 'n_words': 97}