Sha256: fd3891cc2bd81ccdcbdf3f62739790eef2ade6bfe01bbf8783da77af9c400af1

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

require 'ostruct'
require 'delegate'
require 'action_view'
require 'active_support/core_ext/object/blank'
require 'woople_theme_i18n'

class OutlineAssessmentPresenter < SimpleDelegator
  include ActionView::Helpers::TagHelper
  
  def render
    yield if enabled?
  end

  def render_relearnings
    yield unless relearnings.empty?
  end

  def start_button_tag
    css = 'btn btn-primary btn-large'
    
    if url.present?
      content_tag(:a, I18n.t('woople_theme.assessment.start'), class: css, href: url)
    else
      content_tag(:a, I18n.t('woople_theme.assessment.start'), class: "#{css} disabled")
    end
  end

  def history_link_tag
    history.empty? ? '' : content_tag(:a, I18n.t('woople_theme.assessment.history'), class: 'flip-action pull-right')
  end

  def each_history_item
    history.each do |history_item|
      yield normalize(history_item)
    end
  end

  private

  def normalize history_item
    OpenStruct.new(
      date: WoopleThemeI18n.l(history_item.completed_at),
      score: "#{history_item.score}%",
      result_name: history_item.passed ? I18n.t('woople_theme.assessment.pass') : I18n.t('woople_theme.assessment.fail'),
      url: history_item.url
    )
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
woople-theme-0.2.33 app/presenters/outline_assessment_presenter.rb
woople-theme-0.2.32 app/presenters/outline_assessment_presenter.rb
woople-theme-0.2.31 app/presenters/outline_assessment_presenter.rb
woople-theme-0.2.30 app/presenters/outline_assessment_presenter.rb
woople-theme-0.2.29 app/presenters/outline_assessment_presenter.rb
woople-theme-0.2.28 app/presenters/outline_assessment_presenter.rb