Class: DataStructureAssignmentQuestion

Inherits:
DataStructureQuestion show all
Defined in:
lib/battleroom/models/data_structure_assignment_question.rb

Constant Summary collapse

POSSIBLE_INTRO_CONGRATULATIONS =
[
  'Brilliant',
  'Wonderful',
  'Jackpot',
  'Impressive work',
  'Bang-up job',
  'Dynamite',
  'Premier work',
  'Quality work',
  'Terrific'
]

Instance Attribute Summary collapse

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

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_keyObject

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_valueObject

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_classObject

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_valueObject

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_indexObject

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_formattedObject

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_replaceObject

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_formattedObject

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_inputObject



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


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


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