Class: SalesforceCertificationCalculator
- Inherits:
-
Object
- Object
- SalesforceCertificationCalculator
- Defined in:
- lib/salesforce_certification_calculator.rb
Defined Under Namespace
Classes: Exam, FileReader, Section, UI
Instance Attribute Summary collapse
-
#exam ⇒ Exam
Object being used for calculations.
-
#exams ⇒ Array
readonly
Collection of Exam objects used for temporary storage.
Instance Method Summary collapse
-
#calculate_total ⇒ Number
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.
-
#determine_percentage_manually ⇒ Number
Determines cumulative score manually; shortcut that combines all of UI’s methods.
-
#extract_initial_exam_data ⇒ Object
Gets all details about an exam’s sections, including names and weights; shortcut for FileReader method to modify exam attribute on object.
-
#generate_exams_list ⇒ Object
Gets list of all exams in the database, including their names and file paths; shortcut for FileReader method to modify exams attribute on object.
-
#initialize ⇒ SalesforceCertificationCalculator
constructor
Creates SalesforceCertificationCalculator object.
Constructor Details
#initialize ⇒ SalesforceCertificationCalculator
Creates SalesforceCertificationCalculator object
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
#exam ⇒ Exam
Returns object being used for calculations.
7 8 9 |
# File 'lib/salesforce_certification_calculator.rb', line 7 def exam @exam end |
#exams ⇒ Array (readonly)
Returns collection of Exam objects used for temporary storage.
7 |
# File 'lib/salesforce_certification_calculator.rb', line 7 attr_accessor :exam |
Instance Method Details
#calculate_total ⇒ Number
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
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_manually ⇒ Number
Determines cumulative score manually; shortcut that combines all of UI’s methods
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_data ⇒ Object
Gets all details about an exam’s sections, including names and weights; shortcut for FileReader method to modify exam attribute on object
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_list ⇒ Object
Gets list of all exams in the database, including their names and file paths; shortcut for FileReader method to modify exams attribute on object
27 28 29 |
# File 'lib/salesforce_certification_calculator.rb', line 27 def generate_exams_list @exams = @reader.generate_exams_list end |