Class: UqamGradeNotification::Storage::LocalStorage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path = UqamGradeNotification::APP_DIR) ⇒ LocalStorage

Returns a new instance of LocalStorage.



12
13
14
# File 'lib/uqam_grade_notification/storage.rb', line 12

def initialize(base_path=UqamGradeNotification::APP_DIR)
  @base_path = base_path
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



11
12
13
# File 'lib/uqam_grade_notification/storage.rb', line 11

def base_path
  @base_path
end

Instance Method Details

#last_grades(student) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/uqam_grade_notification/storage.rb', line 16

def last_grades(student)
  if File.exist?(grade_file(student))
    JSON.parse File.open(grade_file(student), "rb").read
  else
    ""
  end
end

#save_grades(student) ⇒ Object



24
25
26
# File 'lib/uqam_grade_notification/storage.rb', line 24

def save_grades(student)
  File.write(grade_file(student), student.grades.to_json)
end