Class: AlexCodebreaker::Session
- Inherits:
-
Object
- Object
- AlexCodebreaker::Session
- Includes:
- Modules::ArgumentsValidation
- Defined in:
- lib/alex_codebreaker/session.rb
Constant Summary collapse
- INITIAL_ATTEMPTS_USED =
0
- INITIAL_HINTS_USED =
0
- WINNERS_FILE_NAME =
'/winners.yml'.freeze
Instance Attribute Summary collapse
-
#attempts_total ⇒ Object
readonly
Returns the value of attribute attempts_total.
-
#attempts_used ⇒ Object
readonly
Returns the value of attribute attempts_used.
-
#difficulty_level ⇒ Object
readonly
Returns the value of attribute difficulty_level.
-
#difficulty_name ⇒ Object
readonly
Returns the value of attribute difficulty_name.
-
#hints_total ⇒ Object
readonly
Returns the value of attribute hints_total.
-
#hints_used ⇒ Object
readonly
Returns the value of attribute hints_used.
-
#player_name ⇒ Object
readonly
Returns the value of attribute player_name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #add_difficulty(difficulty) ⇒ Object
- #add_name(given_name) ⇒ Object
- #check_attempts ⇒ Object
- #check_hints ⇒ Object
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #save_winner_statistic ⇒ Object
Methods included from Modules::ArgumentsValidation
#guess_validation, #name_validation
Methods included from Modules::Validators
#argument_length_check, #argument_max_length_check, #argument_min_length_check, #digits_check
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
12 13 14 15 16 |
# File 'lib/alex_codebreaker/session.rb', line 12 def initialize @attempts_used = INITIAL_ATTEMPTS_USED @hints_used = INITIAL_HINTS_USED @time = Time.new end |
Instance Attribute Details
#attempts_total ⇒ Object (readonly)
Returns the value of attribute attempts_total.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def attempts_total @attempts_total end |
#attempts_used ⇒ Object (readonly)
Returns the value of attribute attempts_used.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def attempts_used @attempts_used end |
#difficulty_level ⇒ Object (readonly)
Returns the value of attribute difficulty_level.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def difficulty_level @difficulty_level end |
#difficulty_name ⇒ Object (readonly)
Returns the value of attribute difficulty_name.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def difficulty_name @difficulty_name end |
#hints_total ⇒ Object (readonly)
Returns the value of attribute hints_total.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def hints_total @hints_total end |
#hints_used ⇒ Object (readonly)
Returns the value of attribute hints_used.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def hints_used @hints_used end |
#player_name ⇒ Object (readonly)
Returns the value of attribute player_name.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def player_name @player_name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
9 10 11 |
# File 'lib/alex_codebreaker/session.rb', line 9 def time @time end |
Instance Method Details
#add_difficulty(difficulty) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/alex_codebreaker/session.rb', line 22 def add_difficulty(difficulty) difficulty_level = AlexCodebreaker::Modules::DifficultyLevels::DIFFICULTY_LEVELS[difficulty.downcase.to_sym] return unless difficulty_level @difficulty_name = difficulty_level[:name] @difficulty_level = difficulty_level[:level] @attempts_total = difficulty_level[:attempts_total] @hints_total = difficulty_level[:hints_total] end |
#add_name(given_name) ⇒ Object
18 19 20 |
# File 'lib/alex_codebreaker/session.rb', line 18 def add_name(given_name) @player_name = given_name if name_validation(given_name) end |
#check_attempts ⇒ Object
36 37 38 39 40 41 |
# File 'lib/alex_codebreaker/session.rb', line 36 def check_attempts @attempts_used += 1 return if @attempts_used >= @attempts_total true end |
#check_hints ⇒ Object
32 33 34 |
# File 'lib/alex_codebreaker/session.rb', line 32 def check_hints @hints_used += 1 if @hints_used < @hints_total end |
#save_winner_statistic ⇒ Object
43 44 45 46 47 48 |
# File 'lib/alex_codebreaker/session.rb', line 43 def save_winner_statistic @time = Time.new check_folder_existence path = "#{AlexCodebreaker.configuration.winners_folder_path}#{WINNERS_FILE_NAME}" File.open(path, 'a') { |file| file.write(to_yaml) } end |