Class: Grade

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, score) ⇒ Grade

Returns a new instance of Grade.



37
38
39
40
41
42
43
44
# File 'lib/grade_calculator.rb', line 37

def initialize(id, score)
    if isInvalidScore?(score)
        raise InvalidScoreExceptin.new(score)
    end
    @id = id
    @score = score 
    @grade = calculateGrade(score)
end

Instance Attribute Details

#gradeObject (readonly)

Returns the value of attribute grade.



35
36
37
# File 'lib/grade_calculator.rb', line 35

def grade
  @grade
end

#idObject (readonly)

Returns the value of attribute id.



35
36
37
# File 'lib/grade_calculator.rb', line 35

def id
  @id
end

#scoreObject (readonly)

Returns the value of attribute score.



35
36
37
# File 'lib/grade_calculator.rb', line 35

def score
  @score
end

Instance Method Details

#to_sObject



46
47
48
# File 'lib/grade_calculator.rb', line 46

def to_s
    "#{@id} => #{@grade}: #{@score}"
end