Class: DataStructureAssignmentQuestion
- Inherits:
-
DataStructureQuestion
- Object
- Question
- DataStructureQuestion
- DataStructureAssignmentQuestion
- Defined in:
- lib/battleroom/models/data_structure_assignment_question.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#assignment_key ⇒ Object
Returns the value of attribute assignment_key.
-
#assignment_value ⇒ Object
Returns the value of attribute assignment_value.
-
#assignment_value_class ⇒ Object
Returns the value of attribute assignment_value_class.
-
#formatted_assignment_value ⇒ Object
Returns the value of attribute formatted_assignment_value.
-
#replacement_index ⇒ Object
Returns the value of attribute replacement_index.
-
#replacement_value_class_formatted ⇒ Object
Returns the value of attribute replacement_value_class_formatted.
-
#value_to_replace ⇒ Object
Returns the value of attribute value_to_replace.
-
#value_to_replace_formatted ⇒ Object
Returns the value of attribute value_to_replace_formatted.
Attributes inherited from DataStructureQuestion
#data_structure, #hint, #possible_assignments
Attributes inherited from Question
#answer_value, #data, #data_structure, #data_structure_class, #evaluation_scope, #explanation, #type, #variable_name, #variable_value
Instance Method Summary collapse
- #evaluate_data_structure_assignment_input ⇒ Object
-
#initialize(eval_scope) ⇒ DataStructureAssignmentQuestion
constructor
A new instance of DataStructureAssignmentQuestion.
- #print_resulting_data_structure ⇒ Object
Methods inherited from DataStructureQuestion
#convert_keys_to_strings, #cull_hash_to_valid_size_for_output, #find_number_of_boolean_values_in_hash
Methods inherited from Question
#enter_evaluation_loop, generate_question
Constructor Details
#initialize(eval_scope) ⇒ DataStructureAssignmentQuestion
Returns a new instance of DataStructureAssignmentQuestion.
10 11 12 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 10 def initialize(eval_scope) super(eval_scope) end |
Instance Attribute Details
#assignment_key ⇒ Object
Returns the value of attribute assignment_key.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def assignment_key @assignment_key end |
#assignment_value ⇒ Object
Returns the value of attribute assignment_value.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def assignment_value @assignment_value end |
#assignment_value_class ⇒ Object
Returns the value of attribute assignment_value_class.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def assignment_value_class @assignment_value_class end |
#formatted_assignment_value ⇒ Object
Returns the value of attribute formatted_assignment_value.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def formatted_assignment_value @formatted_assignment_value end |
#replacement_index ⇒ Object
Returns the value of attribute replacement_index.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def replacement_index @replacement_index end |
#replacement_value_class_formatted ⇒ Object
Returns the value of attribute replacement_value_class_formatted.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def replacement_value_class_formatted @replacement_value_class_formatted end |
#value_to_replace ⇒ Object
Returns the value of attribute value_to_replace.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def value_to_replace @value_to_replace end |
#value_to_replace_formatted ⇒ Object
Returns the value of attribute value_to_replace_formatted.
5 6 7 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 5 def value_to_replace_formatted @value_to_replace_formatted end |
Instance Method Details
#evaluate_data_structure_assignment_input ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 35 def evaluate_data_structure_assignment_input enter_evaluation_loop do |user_input| begin # provides the evaluation scope with variable assignment necessary for answer eval evaluation_scope.eval("#{variable_name} = #{data_structure.to_s}") evaluation_scope.eval(user_input) evaluate_user_input(user_input) rescue NoMethodError, NameError => e print_colorized_error_prompt(e) rescue TypeError => e print_colorized_type_error_prompt(e) end end end |
#print_resulting_data_structure ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 14 def print_resulting_data_structure possible_intro_congratulations = [ 'Brilliant', 'Wonderful', 'Jackpot', 'Impressive work', 'Bang-up job', 'Dynamite', 'Premier work', 'Quality work', 'Terrific' ] intro_congrat = possible_intro_congratulations.sample puts "\n#{intro_congrat}. Here's the resulting data structure:\n".green sleep 1.0 resulting_data_structure = evaluation_scope.eval(variable_name) ap(resulting_data_structure, { indent: -2, index: false, multiline: true, plain: true }) puts '' sleep 3.2 end |