Module: Contextualization

Extended by:
ActiveSupport::Concern
Included in:
Assignment, Discussion
Defined in:
app/models/concerns/contextualization.rb

Instance Method Summary collapse

Instance Method Details

#affable_expectation_resultsObject

Affable results



115
116
117
118
119
120
121
122
# File 'app/models/concerns/contextualization.rb', line 115

def affable_expectation_results
  visible_expectation_results.map do |it|
    {
      result: it[:result],
      explanation: Mulang::Expectation.parse(it).translate(inspection_keywords).affable
    }
  end
end

#affable_test_resultsObject



128
129
130
131
132
133
134
135
136
137
# File 'app/models/concerns/contextualization.rb', line 128

def affable_test_results
  test_results.to_a.map do |it|
    { summary: it.dig(:summary, :message).affable }
      .compact
      .merge(
        title: it[:title].affable,
        result: it[:result],
        status: it[:status])
  end
end

#affable_tipsObject



124
125
126
# File 'app/models/concerns/contextualization.rb', line 124

def affable_tips
  tips.map(&:affable)
end

#expectation_results_visible?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/models/concerns/contextualization.rb', line 93

def expectation_results_visible?
  failed_expectation_results.present?
end

#failed_expectation_resultsObject



89
90
91
# File 'app/models/concerns/contextualization.rb', line 89

def failed_expectation_results
  expectation_results.to_a.select { |it| it[:result].failed? }.uniq
end

#feedback_htmlObject



85
86
87
# File 'app/models/concerns/contextualization.rb', line 85

def feedback_html
  output_content_type.to_html(feedback)
end

#first_test_resultObject



57
58
59
# File 'app/models/concerns/contextualization.rb', line 57

def first_test_result
  test_results.first
end

#first_test_result_htmlObject



61
62
63
# File 'app/models/concerns/contextualization.rb', line 61

def first_test_result_html
  test_result_html first_test_result
end

#humanized_expectation_resultsObject



101
102
103
104
105
106
107
108
109
# File 'app/models/concerns/contextualization.rb', line 101

def humanized_expectation_results
  warn "Don't use humanized_expectation_results. Use affable_expectation_results, which also handles markdown and sanitization"
  visible_expectation_results.map do |it|
    {
      result: it[:result],
      explanation: Mulang::Expectation.parse(it).translate(inspection_keywords)
    }
  end
end

#iconizeObject



77
78
79
# File 'app/models/concerns/contextualization.rb', line 77

def iconize
  visible_status.iconize
end

#queries_with_resultsObject



33
34
35
36
37
# File 'app/models/concerns/contextualization.rb', line 33

def queries_with_results
  queries.zip(query_results).map do |query, result|
    {query: query, status: result&.dig(:status).defaulting(:pending), result: result&.dig(:result)}
  end
end

#result_htmlObject



81
82
83
# File 'app/models/concerns/contextualization.rb', line 81

def result_html
  output_content_type.to_html(result)
end

#results_body_hidden?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/concerns/contextualization.rb', line 69

def results_body_hidden?
  (passed? && !visible_success_output?) || exercise.choice? || manual_evaluation_pending? || skipped?
end

#sanitized_affable_test_resultsObject



139
140
141
# File 'app/models/concerns/contextualization.rb', line 139

def sanitized_affable_test_results
  affable_test_results.each { |it| it[:result] = it[:result]&.sanitized }
end

#single_visible_test_result?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/concerns/contextualization.rb', line 53

def single_visible_test_result?
  test_results.single? && visible_success_output?
end

#single_visual_result?Boolean

deprecated: this method does hidden assumptions about the UI not wanting non-empty titles to not be displayed. Also it incorrectly uses the term ‘visual` instead of `visible`

Returns:

  • (Boolean)


41
42
43
44
# File 'app/models/concerns/contextualization.rb', line 41

def single_visual_result?
  warn 'use single_visible_test_result? instead'
  single_visible_test_result? && first_test_result[:title].blank?
end

#single_visual_result_htmlObject

deprecated: this method does not validate nor depends on any ‘visible` condition Also, it incorrectly uses the term `visual` instead of `visible`



48
49
50
51
# File 'app/models/concerns/contextualization.rb', line 48

def single_visual_result_html
  warn 'use first_test_result_html intead'
  first_test_result_html
end

#test_result_html(test_result) ⇒ Object



65
66
67
# File 'app/models/concerns/contextualization.rb', line 65

def test_result_html(test_result)
  output_content_type.to_html test_result[:result]
end

#visible_expectation_resultsObject



97
98
99
# File 'app/models/concerns/contextualization.rb', line 97

def visible_expectation_results
  exercise.input_kids? ? failed_expectation_results.first(1) : failed_expectation_results
end

#visible_statusObject



73
74
75
# File 'app/models/concerns/contextualization.rb', line 73

def visible_status
  status
end