Sha256: be0f190da94df131f83f3578dba6b9036c6efcad61201890d26ae81316746bb7

Contents?: true

Size: 1.35 KB

Versions: 30

Compression:

Stored size: 1.35 KB

Contents

require 'action_view'
require 'woople_theme_i18n'

class SubmittedAssessmentFormPresenter < AssessmentFormPresenter
  include ActionView::Helpers::NumberHelper
  include ActionView::Helpers::TagHelper

  enforce_definitions :completed_at,
                      :passed?,
                      :correct_questions,
                      :score

  def title
    I18n.t('woople_theme.assessment.result')
  end

  def css_classes
    [:results]
  end

  def questions
    ThemePresentation.wrap_collection(__getobj__.questions, WoopleTheme::SubmittedQuestionPresenter)
  end

  def render_result_status
    status_message = I18n.t('woople_theme.assessment.result_status', {
      completed_at: WoopleThemeI18n.l(completed_at.to_date),
      status: status,
      correct_questions: correct_questions,
      total_questions: total_questions,
      score: number_to_percentage(score, :precision => 0),
      count: total_questions
    })

    yield OpenStruct.new(message: status_message, classes: result_status_classes)
  end

  def footer_partial
    'woople-theme/assessment_form_return'
  end

  def result_status_classes
    css_classes = [:alert]
    css_classes << (passed? ? 'alert-success' : 'alert-error')
  end

  def status
    passed? ? I18n.t('woople_theme.assessment.passed') : I18n.t('woople_theme.assessment.failed')
  end

  def total_questions
    questions.length
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
woople-theme-0.6.11 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.10 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.9 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.8 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.7 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.6 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.5 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.4 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.3 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.2 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6.1 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.6 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.17 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.16 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.15 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.14 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.13 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.12 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.11 app/presenters/submitted_assessment_form_presenter.rb
woople-theme-0.5.10 app/presenters/submitted_assessment_form_presenter.rb