Class: DataStructureAssignmentQuestion
- Inherits:
-
DataStructureQuestion
- Object
- Question
- DataStructureQuestion
- DataStructureAssignmentQuestion
- Defined in:
- lib/battleroom/models/data_structure_assignment_question.rb
Direct Known Subclasses
Constant Summary collapse
- POSSIBLE_INTRO_CONGRATULATIONS =
[ 'Brilliant', 'Wonderful', 'Jackpot', 'Impressive work', 'Bang-up job', 'Dynamite', 'Premier work', 'Quality work', 'Terrific' ]
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, #input_mechanism, #user_input, #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_data_structure ⇒ Object
- #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
#congratulation_sequence, #enter_evaluation_loop, generate_question, #get_input, #handle_syntax_error_exceptions
Constructor Details
#initialize(eval_scope) ⇒ DataStructureAssignmentQuestion
Returns a new instance of DataStructureAssignmentQuestion.
22 23 24 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 22 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 42 def evaluate_data_structure_assignment_input enter_evaluation_loop do |user_submission| 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_submission) evaluate_user_input(user_submission) rescue NoMethodError, NameError => e print_colorized_error_prompt(e) rescue TypeError => e print_colorized_type_error_prompt(e) end end end |
#print_data_structure ⇒ Object
26 27 28 29 30 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 26 def print_data_structure print "#{variable_name} = ".green ap(data_structure, { indent: -2, index: false, multiline: true, plain: true }) battleprint '' end |
#print_resulting_data_structure ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/battleroom/models/data_structure_assignment_question.rb', line 32 def print_resulting_data_structure intro_congrat = POSSIBLE_INTRO_CONGRATULATIONS.sample battleprint "\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 }) battleprint '' sleep 3.2 end |