Module: StatisticsHelper
- Defined in:
- lib/statistics_helper.rb
Constant Summary collapse
- SYMBOLS =
An array of all the symbols to be availble to the user
['#', '`', '%', '&', '[', '{', '}', '(', '=', '*', ')', '+', ']', '!', '|', '-', '_', '@', '^', '/', '?', '<', '>', '$', '~', ';', ':'].freeze
Class Method Summary collapse
-
.add_symbols_to_hash ⇒ Object
This is called when there is no data stored in the JSON file.
-
.create_symbol_array ⇒ Object
create a randomized array of symbols to guess.
-
.create_targeted_array ⇒ Object
This is a method to get the last 8 keys from the user to make into a new array for targeted practice.
-
.randomized_targeted_array ⇒ Object
This method creates a randomized array with the worst 8 keys, all represented 3 times and shuffled.
Class Method Details
.add_symbols_to_hash ⇒ Object
This is called when there is no data stored in the JSON file. It outputs a hash with all the symbols and sets all values to 0
45 46 47 48 49 50 51 |
# File 'lib/statistics_helper.rb', line 45 def self.add_symbols_to_hash typing_statistics = {} SYMBOLS.each do |item| typing_statistics[item] = [0, 0, 0, 0, 0] end typing_statistics end |
.create_symbol_array ⇒ Object
create a randomized array of symbols to guess
8 9 10 11 12 13 14 15 16 |
# File 'lib/statistics_helper.rb', line 8 def self.create_symbol_array randomized_array = [] # choose a random symbol out of the array and append to a new array. 15.times do randomized_array << SYMBOLS.sample end # ensure that all elements in the array are unique randomized_array end |
.create_targeted_array ⇒ Object
This is a method to get the last 8 keys from the user to make into a new array for targeted practice
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statistics_helper.rb', line 19 def self.create_targeted_array worst_key_array = [] # Read the users statistics from the file, if there is no data in the file, create an object with 0 as values begin typing_statistics = TypingStatistics.new.read_statistics rescue JSON::ParserError typing_statistics = add_symbols_to_hash end # Get the last 8 hash elements (The users worst keys), by revesing hash and getting the first 8 elements worst_keys = typing_statistics.reverse_each.to_h.first(8) worst_keys.each do |key| worst_key_array << key[0] end worst_key_array end |
.randomized_targeted_array ⇒ Object
This method creates a randomized array with the worst 8 keys, all represented 3 times and shuffled.
36 37 38 39 40 41 42 |
# File 'lib/statistics_helper.rb', line 36 def self.randomized_targeted_array randomized_array = [] 3.times do randomized_array << create_targeted_array.shuffle end randomized_array.flatten end |