Class: SalesforceCertificationCalculator

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

Defined Under Namespace

Classes: Exam, FileReader, Section, UI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSalesforceCertificationCalculator

Creates SalesforceCertificationCalculator object

Examples:

Create Calculator Object

>> calculator = SalesforceCertificationCalculator.new


14
15
16
17
18
19
# File 'lib/salesforce_certification_calculator.rb', line 14

def initialize
    @exams = []
    @exam = Exam.new
    @reader = FileReader.new
    @ui = UI.new
end

Instance Attribute Details

#examExam

Returns object being used for calculations.

Returns:

  • (Exam)

    object being used for calculations



7
8
9
# File 'lib/salesforce_certification_calculator.rb', line 7

def exam
  @exam
end

#examsArray (readonly)

Returns collection of Exam objects used for temporary storage.

Returns:

  • (Array)

    collection of Exam objects used for temporary storage



7
# File 'lib/salesforce_certification_calculator.rb', line 7

attr_accessor :exam

Instance Method Details

#calculate_totalNumber

Determines cumulative score for the exam based on its sections’ weights and scores; shortcut for Exam method that returns total value of exam after calculating total

Examples:

Calculate Total

>> calculator = SalesforceCertificationCalculator.new
>> total = calculator.calculate_total
=> 87

Returns:

  • (Number)

    cumulative score on exam; if sections’ weights do not sum to 100, it will return an error message as a string



51
52
53
54
55
# File 'lib/salesforce_certification_calculator.rb', line 51

def calculate_total
    @exam.calculate_total

    return @exam.total
end

#determine_percentage_manuallyNumber

Determines cumulative score manually; shortcut that combines all of UI’s methods

Examples:

Calculate Total

>> calculator = SalesforceCertificationCalculator.new
>> total = calculator.determine_percentage_manually
=> 87

Returns:

  • (Number)

    cumulative score on exam



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/salesforce_certification_calculator.rb', line 65

def determine_percentage_manually
    choice = @ui.select_list_or_new

    if choice == "LIST"
        # Get list of exams, prompt user to select one, then require user to provide their scores for all the exam's sections
        @exams = @reader.generate_exams_list
        @exam = @ui.select_specific_exam(@exams)

        # Only proceed if user did not end up entering data manually after not finding their exam listed
        if @exam.sections.length == 0
            @exam = @reader.extract_initial_exam_data(@exam)

            puts "You selected: #{@exam.title}"
            puts "Enter your scores for each of the exam's #{@exam.sections.length} sections in the order you are prompted"
            
            @exam = @ui.provide_scores(@exam)
        end
    else
        # Allow user to manually enter all data themselves without the aid of the data already stored in the module's XML files
        @exam = @ui.provide_all_details_manually
    end

    @exam.calculate_total

    puts "Your cumulative score is: #{@exam.total}%"

    return @exam.total
end

#extract_initial_exam_dataObject

Gets all details about an exam’s sections, including names and weights; shortcut for FileReader method to modify exam attribute on object

Examples:

Retrieve Exam Data

>> calculator = SalesforceCertificationCalculator.new
>> calculator.generate_exams_list
>> calculator.exam = calculator.exams[1]
>> calculator.extract_exam_data
=> <SalesforceCertificationCalculator::Exam 0x000987>


39
40
41
# File 'lib/salesforce_certification_calculator.rb', line 39

def extract_initial_exam_data
    @exam = @reader.extract_initial_exam_data(@exam)
end

#generate_exams_listObject

Gets list of all exams in the database, including their names and file paths; shortcut for FileReader method to modify exams attribute on object

Examples:

Retrieve Exams

>> calculator = SalesforceCertificationCalculator.new
>> exams = calculator.generate_exams_list
=> [<SalesforceCertificationCalculator::Exam 0x000987>, <SalesforceCertificationCalculator::Exam 0x000988>]


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

def generate_exams_list
    @exams = @reader.generate_exams_list
end