salesforce_certification_calculator 0.2.2 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c567ac0623c7dd10af68535253e5e41940c3bb95a40f4d4bf949db7ab66c6fdc
4
- data.tar.gz: 5199c2d3b10aa5be6ee0f8d4c7a017b074cd273895af7998a173dd338dc67480
3
+ metadata.gz: a085ce0eb296c739f492519f11e1e11ed162423632aa115cb1e73aa66eb3c8e6
4
+ data.tar.gz: 76e04f4e08be8de4708986ec1609a0226d9c75a67cc01718d24d3dc55465c28f
5
5
  SHA512:
6
- metadata.gz: 9958c6e030202ee90903b6305bbf0279d87e0ed98e8c24c9c8d398b3ac6913bc2bd21cd9fdb3f4c0be41cb9b59c419565ad19a21de39a9811a4d1a2de970f084
7
- data.tar.gz: 4d4b26d5210bb43bc701302579205897e654eeab15324d0429fa985ea9550845171b1961d16171f0442024e648b8810e55be37dbf1dbe7593f7cc7ac74a1e83d
6
+ metadata.gz: 6c6b97f0d765f336d447914fc9e870a94646e4a80858e5fbc6442eca0e2210f7fc20aff23e375985fe07d12cd4ab042bc34e050b12a0668ba00df481ae032f1a
7
+ data.tar.gz: f31d416f959c4aeb42d3d29ebdf966d538aa7805965aecff6840b8a17ced8a9e13771c4ea03ba4bfbb705cb3984eb655f004663e9c41e1e5a2e13569490c5731
data/README.md CHANGED
@@ -28,6 +28,7 @@ I've taken a few Salesforce certification exams in my day, and I was always anno
28
28
  - File reading functionality
29
29
  - User interface for the CLI to provide prompts to walk user through the input process
30
30
  - Methods for calculating the cumulative total and for walking the user through all stages of data collection
31
+ - Executable to allow user to run the module's core functionality with a simple command in the CLI instead of needing to go into a Ruby shell
31
32
 
32
33
  ## Requirements
33
34
 
@@ -65,14 +66,16 @@ If you have trouble downloading the package or just want to play around with the
65
66
  1. Fork this repository
66
67
  2. Clone it to your local computer
67
68
  3. From within your local version of the directory, build the module: `gem build salesforce_certification_calculator.gemspec`
68
- 4. Then install that built module: `gem install ./salesforce_certification_calculator-0.2.2.gem`
69
+ 4. Then install that built module: `gem install ./salesforce_certification_calculator-0.2.5.gem`
69
70
  5. Open a Ruby environment to use the module: `irb`
70
71
  6. Execute any of the recently installed methods
71
72
 
72
- You may need to update the specific version of the build as later releases come out (e.g., `-0.2.2.gem` may need to become `-0.3.0.gem`).
73
+ You may need to update the specific version of the build as later releases come out (e.g., `-0.2.5.gem` may need to become `-0.3.0.gem`).
73
74
 
74
75
  ## Usage
75
76
 
77
+ ### Module
78
+
76
79
  1. Open a Ruby environment to use the module: `irb`
77
80
  2. Require the package: `require 'salesforce_certification_calculator'`
78
81
  3. Create a new calculator to use: `calculator = SalesforceCertificationCalculator.new`
@@ -81,6 +84,14 @@ You may need to update the specific version of the build as later releases come
81
84
 
82
85
  Of course, you may use any of the other methods provided by the package, but `determine_percentage_manually` is the core method.
83
86
 
87
+ ### Executable
88
+
89
+ This package also contains an executable, so you can run its core functionality (the above `determine_percentage_manually` method) directly from the CLI without needing to enter a Ruby shell:
90
+
91
+ ```
92
+ salesforce_certification_calculator
93
+ ```
94
+
84
95
  ## Documentation
85
96
 
86
97
  This project uses **YARD** for documentation generation. To view the published form, see the [documentation on the RubyDoc site](https://www.rubydoc.info/gems/salesforce_certification_calculator/). To view the docs locally, go to the `doc` folder. To generate the docs yourself, execute `rake yard` in the CLI from the root of your local copy of the project.
@@ -99,6 +110,8 @@ def calculate_total
99
110
 
100
111
  if summed_weights != 100
101
112
  @total = "CANNOT CALCULATE"
113
+ else
114
+ @total = @total.round(2)
102
115
  end
103
116
  end
104
117
  ```
@@ -106,7 +119,8 @@ end
106
119
  **Helper function to pull data stored in a reference XML file**
107
120
  ```ruby
108
121
  def extract_initial_exam_data(exam)
109
- doc = File.open(exam.file) { |f| Nokogiri::XML(f) }
122
+ file_path = @base_path + "/" + exam.file
123
+ doc = File.open(file_path) { |f| Nokogiri::XML(f) }
110
124
  names = doc.xpath("//name")
111
125
  weights = doc.xpath("//weight")
112
126
 
@@ -120,7 +134,7 @@ end
120
134
 
121
135
  ## Testing
122
136
 
123
- This project has 103 automated tests, located in the `test` folder at the root. To run them, execute `rake test`. In order to successfully run these tests, you may need to also install `stringio` and `o_stream_catcher`.
137
+ This project has 106 automated tests, located in the `test` folder at the root. To run them, execute `rake test`. In order to successfully run these tests, you may need to also install `stringio` and `o_stream_catcher`.
124
138
 
125
139
  ## Future Goals
126
140
 
data/Rakefile CHANGED
@@ -12,4 +12,4 @@ end
12
12
  desc "Run tests"
13
13
  task default: :test
14
14
 
15
- # --- Ran 103 tests in 0.013676s on 7/28/22 --- OK --- #
15
+ # --- Ran 106 tests in 0.013781s on 7/30/22 --- OK --- #
@@ -48,12 +48,13 @@ class SalesforceCertificationCalculator::Exam
48
48
  def calculate_total
49
49
  summed_weights = 0
50
50
 
51
+ # Sum weighted scores of all sections
51
52
  @sections.each do |section|
52
53
  summed_weights += section.weight
53
54
  @total += section.weight * section.score / 100.0
54
55
  end
55
56
 
56
- # Sets total to error message when sum of sections' weights is not 100
57
+ # Sets total to error message when sum of sections' weights is not 100; otherwise, rounds answer
57
58
  if summed_weights != 100
58
59
  @total = "CANNOT CALCULATE"
59
60
  else
@@ -8,18 +8,22 @@ class SalesforceCertificationCalculator::FileReader
8
8
  def initialize
9
9
  sfc_gems = []
10
10
 
11
+ # Get full path to where Ruby gems are stored on user's computer, starting at the base
11
12
  gems_path = ENV["HOME"] + "/gems/gems"
12
13
  all_gems = Dir.children(gems_path)
13
14
 
15
+ # Create list of all versions of module installed on user's computer
14
16
  all_gems.each do |gem|
15
17
  if gem.include? "salesforce_certification_calculator"
16
18
  sfc_gems.push(gem)
17
19
  end
18
20
  end
19
21
 
22
+ # Determine most recent version of module available
20
23
  sfc_gems.sort
21
24
  latest_sfc = sfc_gems[sfc_gems.length - 1]
22
25
 
26
+ # Set path variable for use by the class's methods
23
27
  @base_path = gems_path + "/" + latest_sfc
24
28
  end
25
29
 
@@ -35,6 +39,7 @@ class SalesforceCertificationCalculator::FileReader
35
39
  exams = []
36
40
  files = Dir.glob("data/*xml", base: @base_path)
37
41
 
42
+ # Create list of all exams, including their titles and file paths
38
43
  files.each do |file|
39
44
  exam = SFC::Exam.new
40
45
  file_path = @base_path + "/" + file
@@ -65,6 +70,7 @@ class SalesforceCertificationCalculator::FileReader
65
70
  names = doc.xpath("//name")
66
71
  weights = doc.xpath("//weight")
67
72
 
73
+ # Add all sections' names and weights to existing exam data
68
74
  (0..names.length-1).each do |i|
69
75
  exam.add_section(names[i].content, weights[i].content.to_i)
70
76
  end
@@ -13,6 +13,7 @@ class SalesforceCertificationCalculator::UI
13
13
  puts "Do you want to select an exam from a list (enter LIST), or do you want to type in your own details (enter NEW)?"
14
14
  choice = gets.chomp
15
15
 
16
+ # Only return value if user selected one of the two provided options; otherwise, recursively recall function
16
17
  if choice == "LIST" || choice == "NEW"
17
18
  return choice
18
19
  else
@@ -33,18 +34,28 @@ class SalesforceCertificationCalculator::UI
33
34
  #
34
35
  # @return [Exam] object with name, file, and section details for selected exam
35
36
  def select_specific_exam(exams)
37
+ exams_length = exams.length
38
+
36
39
  puts "Your choices are:"
37
40
 
41
+ # List exam options
38
42
  exams.each do |exam|
39
43
  puts "#{exams.find_index(exam) + 1} - #{exam.title}"
40
44
  end
41
45
 
46
+ # Add option to take user back to the LIST or NEW prompt
47
+ puts "#{exams_length + 1} - NOT LISTED"
42
48
  puts "Which one would you like to select? Enter the number before the exam name:"
43
49
  choice = gets.chomp.to_i
44
50
 
45
- if choice.between?(1, exams.length)
51
+ if choice.between?(1, exams_length)
52
+ # Only return value if user inputted number within range
46
53
  return exams[choice - 1]
54
+ elsif choice == exams_length + 1
55
+ # Allow user to opt out if last option entered
56
+ select_list_or_new()
47
57
  else
58
+ # Recursively recall function if invalid input
48
59
  select_specific_exam(exams)
49
60
  end
50
61
  end
@@ -65,6 +76,7 @@ class SalesforceCertificationCalculator::UI
65
76
  def provide_scores(exam)
66
77
  sections = exam.sections
67
78
 
79
+ # Get scores for each section from the user
68
80
  sections.each do |section|
69
81
  puts "#{section.name} is worth #{section.weight}%"
70
82
  puts "What score did you get on that section? (enter an integer)"
@@ -90,6 +102,7 @@ class SalesforceCertificationCalculator::UI
90
102
  puts "How many sections does it have?"
91
103
  length = gets.chomp.to_i
92
104
 
105
+ # Get names, weights, and scores for each section of the exam from the user
93
106
  (1..length).each do |i|
94
107
  puts "What is the name of Section #{i}?"
95
108
  name = gets.chomp
@@ -66,6 +66,7 @@ class SalesforceCertificationCalculator
66
66
  choice = @ui.select_list_or_new
67
67
 
68
68
  if choice == "LIST"
69
+ # Get list of exams, prompt user to select one, then require user to provide their scores for all the exam's sections
69
70
  @exams = @reader.generate_exams_list
70
71
  @exam = @ui.select_specific_exam(@exams)
71
72
  @exam = @reader.extract_initial_exam_data(@exam)
@@ -75,6 +76,7 @@ class SalesforceCertificationCalculator
75
76
 
76
77
  @exam = @ui.provide_scores(@exam)
77
78
  else
79
+ # Allow user to manually enter all data themselves without the aid of the data already stored in the module's XML files
78
80
  @exam = @ui.provide_all_details_manually
79
81
  end
80
82
 
data/test/test_u_i.rb CHANGED
@@ -184,6 +184,20 @@ class UITest < Minitest::Test
184
184
  assert_equal 1, result[1].scan("Which one would you like to select").length, "should call select_specific_exam only once if user inputs 2"
185
185
  end
186
186
 
187
+ def test_select_specific_exam_call_list_new
188
+ result = OStreamCatcher.catch do
189
+ string_io = StringIO.new
190
+ string_io.puts "#{@@exams.length + 1}"
191
+ string_io.puts "NEW"
192
+ string_io.rewind
193
+ $stdin = string_io
194
+ @@ui.select_specific_exam(@@exams)
195
+ $stdin = STDIN
196
+ end
197
+
198
+ assert_equal 1, result[1].scan("Do you want to select an exam from a list (enter LIST), or do you want to type in your own details (enter NEW)?").length, "should call select_list_or_new if user enters NOT LISTED option"
199
+ end
200
+
187
201
  def test_select_specific_exam_recursion_greater
188
202
  result = OStreamCatcher.catch do
189
203
  string_io = StringIO.new
@@ -212,6 +226,34 @@ class UITest < Minitest::Test
212
226
  assert_operator result[1].scan("Which one would you like to select").length, :>, 1, "should call select_specific_exam more than once if user inputs 0"
213
227
  end
214
228
 
229
+ def test_select_specific_exam_recursion_letter
230
+ result = OStreamCatcher.catch do
231
+ string_io = StringIO.new
232
+ string_io.puts "a"
233
+ string_io.puts "1"
234
+ string_io.rewind
235
+ $stdin = string_io
236
+ @@ui.select_specific_exam(@@exams)
237
+ $stdin = STDIN
238
+ end
239
+
240
+ assert_operator result[1].scan("Which one would you like to select").length, :>, 1, "should call select_specific_exam more than once if user inputs letter"
241
+ end
242
+
243
+ def test_select_specific_exam_recursion_title
244
+ result = OStreamCatcher.catch do
245
+ string_io = StringIO.new
246
+ string_io.puts "Advanced Administrator"
247
+ string_io.puts "1"
248
+ string_io.rewind
249
+ $stdin = string_io
250
+ @@ui.select_specific_exam(@@exams)
251
+ $stdin = STDIN
252
+ end
253
+
254
+ assert_operator result[1].scan("Which one would you like to select").length, :>, 1, "should call select_specific_exam more than once if user inputs title of exam instead of number"
255
+ end
256
+
215
257
  def test_provide_scores_returns_exam
216
258
  result = {}
217
259
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_certification_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jackson Reeves