-
-
Save roktas/68a29c4b7b5cab18fb9986d0afd10136 to your computer and use it in GitHub Desktop.
Akademik takvim tarih aralıkları
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarEvent < ApplicationRecord | |
def proper_range? | |
Time.zone.now >= start_date && Time.zone.now <= end_date | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class CalendarTitle < ApplicationRecord | |
class << self | |
def registery | |
@registery ||= Event.registery_from_yaml 'calendar_titles.yml' | |
end | |
def self.find_by_event_code(code) | |
find_by(name: registery(code).title) | |
end | |
end | |
end | |
# Usage | |
# CalendarTitle.course_registration | |
CalendarTitle.find_by_event_code 'course.registration' | |
# => CalendarTitle Load (0.5ms) SELECT "calendar_titles".* FROM "calendar_titles" WHERE "calendar_titles"."name" = $1 LIMIT $2 [["name", "Ders Kayıtları"], ["LIMIT", 1]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
course: | |
- name: registration | |
title: Ders Kayıtları | |
- name: add_and_drop | |
title: Ders Ekleme ve Bırakma | |
- name: start_date | |
title: Derslerin Başlaması | |
- name: end_date | |
title: Derslerin Bitimi | |
exam: | |
- name: midterm_date | |
title: Ara Sınav Haftası | |
- name: final_date | |
title: Yarıyıl Sonu Sınav Haftası | |
- name: submission_final_date | |
title: Yarıyıl Sonu Sınav Sonuçlarının İnternetten Girilmesinin Son Günü ve Sonuçların İlanı | |
- name: makeup_date | |
title: Bütünleme Sınav Haftası | |
- name: submission_makeup_date | |
title: Bütünleme Sınav Sonuçlarının İnternetten Girilmesinin Son Günü ve Sonuçların İlanı | |
- name: single_course | |
title: Tek Ders Sınavları | |
- name: submission_single_course | |
title: Tek Ders Sınav Sonuçlarının ÖİDB'ye Gönderilmesi | |
- name: foreign_language_proficiency | |
title: Zorunlu Hazırlık Sınıfları Yabancı Dil Yeterlik Sınavı | |
- name: submission_proficiency | |
title: Yeterlik Sınav Sonuçlarının İlanı | |
- name: foreign_language_exemption | |
title: Yabancı Dil Muafiyet Sınavları (5/i Dersleri İçin) | |
- name: grading | |
title: Hazırlık Sınıfları İçin Düzey Belirleme Sınavı | |
application: | |
- name: major_and_minor | |
title: Çift Anadal ve Yandal Başvuruları | |
- name: submission_major_and_minor | |
title: Çift Anadal ve Yandal Başvurularının Birimlerce Değerlendirilmesi ve İlanı | |
- name: exclusivly_course | |
title: Mazeretli Ders Kaydı Başvuruları Son Günü | |
- name: single_course | |
title: Tek Ders Sınav Müracaatları |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student < ApplicationRecord | |
def proper_event_range?(title) | |
academic_calendars.last.calendar_events.find_by(calendar_title_id: CalendarTitle.send(title)).proper_range? | |
end | |
end | |
# Öğrencinin ders kaydını yapıp yapamayacağını sorgulamak için: | |
# @student.proper_event_range?(:course_registration) | |
# Öğrencinin çift anadal ve yandal başvurusunu yapıp yapamayacağını sorgulamak için: | |
# @student.proper_event_range?(:application_major_and_minor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'yaml' | |
require 'active_support' | |
require 'active_support/core_ext' | |
require 'ap' | |
class Event | |
Datum = Struct.new :name, :title, :start_date, :end_date, keyword_init: true | |
class Type | |
delegate :name, :title, :start_date, :end_date, to: :@datum | |
attr_reader :path, :code | |
def initialize(path, **datum) | |
@datum = Datum.new(**datum) | |
@path = path | |
@code = encode | |
end | |
private | |
PATH_SEPARATOR = '.' | |
def encode | |
[*path, name].map(&:to_s).join PATH_SEPARATOR | |
end | |
end | |
def self.registery_from_yaml(yaml_file) | |
registery = ActiveSupport::OrderedOptions.new | |
# TODO: rastgele derinlikte veri yapılarını da idare edebilir | |
YAML.load_file(yaml_file).each do |category, data| | |
data.each do |datum| | |
type = Type.new([category], **datum.deep_symbolize_keys) | |
registery[type.code] = type | |
end | |
end | |
registery | |
end | |
end | |
registery = Event.registery_from_yaml 'calendar_titles.yml' | |
ap registery | |
# registery.each do |_, type| | |
# ap type.code | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment