Class: UqamGradeNotification::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/uqam_grade_notification/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(student, notifier, storage) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
# File 'lib/uqam_grade_notification/client.rb', line 5

def initialize(student, notifier, storage)
  @student = student
  @notifier = notifier
  @storage = storage
end

Instance Attribute Details

#notifierObject (readonly)

Returns the value of attribute notifier.



3
4
5
# File 'lib/uqam_grade_notification/client.rb', line 3

def notifier
  @notifier
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/uqam_grade_notification/client.rb', line 3

def storage
  @storage
end

#studentObject (readonly)

Returns the value of attribute student.



3
4
5
# File 'lib/uqam_grade_notification/client.rb', line 3

def student
  @student
end

Instance Method Details

#grades_have_changed?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/uqam_grade_notification/client.rb', line 22

def grades_have_changed?
  md5 = Digest::MD5.new
  md5.hexdigest(student.grades.to_json) == md5.hexdigest(student_last_grades.to_json)
end

#notify_of_changesObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/uqam_grade_notification/client.rb', line 11

def notify_of_changes
  if grades_have_changed?
    p "Grades have not changed since last checked."
  else
    message = "Your grades have been updated!"
    p message
    save_student_grades
    notifier.sms(message)
  end
end

#save_student_gradesObject



31
32
33
# File 'lib/uqam_grade_notification/client.rb', line 31

def save_student_grades
  storage.save_grades(student)
end

#student_last_gradesObject



27
28
29
# File 'lib/uqam_grade_notification/client.rb', line 27

def student_last_grades
  @last_grades ||= storage.last_grades(student)
end