<commit_before>module Bookings
  class AppointmentSerializer < ActiveModel::Serializer
    attributes :id, :start, :end, :title, :recurring
    #TODO HZ: refactor, add attribute time_slot
    def recurring
      begin
        object.recurring
      rescue 
        nil
      end
    end

    #TODO HZ: get start_day from configuration
    def beginning_of_this_week
      DateTime.now.beginning_of_week(start_day= :sunday)
    end

    def week_days
      DateTime::DAYNAMES
    end

    def start
      begin
        object.recurring
        h_m = object.to_time.split(':')
        format_date h_m
      rescue
        object.from_time
      end
    end

    def end
      begin
        object.recurring
        h_m = object.to_time.split(':')
        format_date h_m
      rescue
        object.to_time
      end
    end

    def title
      object.id
    end

    private
    def format_date(hour_minute)
      day = beginning_of_this_week
      day + week_days.index(object.day) + hour_minute[0].to_i.hour + hour_minute[1].to_i.minute
    end
  end
end<commit_msg>refactor serializer, add new field time_slot to distinguish between appointment and time slot<commit_after>module Bookings
  class AppointmentSerializer < ActiveModel::Serializer
    attributes :id, :start, :end, :title, :recurring, :time_slot

    def recurring
      begin
        object.recurring
      rescue 
        nil
      end
    end

    def time_slot
      begin
        true if object.recurring
      rescue 
        false
      end
    end

    def start
      object.from_time
    end

    def end
      object.to_time
    end

    def title
      object.id
    end
  end
end
{'fraction_non_alphanumeric': 0.0548854041013269, 'fraction_numerical': 0.0012062726176115801, 'mean_word_length': 1.9945848375451263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4886038', 'n_tokens_mistral': 522, 'n_tokens_neox': 509, 'n_words': 135}