Sha256: 0b516ec5b28787249a45ed9f00402ac99856be89081197d5d57c563dab22ce6b

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'forwardable'
require 'action_view/helpers/url_helper'
require 'explicit_delegator'

module WoopleTheme
  module Reports
    class PersonalReportPresenter < ExplicitDelegator
      include ActionView::Helpers::UrlHelper

      enforce_definitions :name, :type, :data_path, :download_path

      DAILY_LEGEND   = ['0-3', '4-6', '7+']
      WEEKLY_LEGEND  = ['0-28', '29-48', '49+']
      MONTHLY_LEGEND = ['0-123', '124-216', '217+']

      def report_link
        link_to(
          name,
          href,
          {
            data: {
              toggle: 'tab',
              type: type,
              container: container,
              path: data_path
            }
          }
        )
      end

      def name
        report.name.titleize
      end

      def tab_name
        report.type.downcase
      end

      def href
        "##{tab_name}"
      end

      def container
        "#{tab_name}_report_chart"
      end

      def legend
        return DAILY_LEGEND if daily?
        return WEEKLY_LEGEND if weekly?
        return MONTHLY_LEGEND if monthly?
      end

      def chart_title
        return I18n.t('woople_theme.reports.chart.titles.daily') if daily?
        return I18n.t('woople_theme.reports.chart.titles.weekly') if weekly?
        return I18n.t('woople_theme.reports.chart.titles.monthly') if monthly?
      end

      def daily?
        report.type.to_s == 'week'
      end

      def weekly?
        report.type.to_s == 'month'
      end

      def monthly?
        report.type.to_s == 'annual'
      end

      private

      def report
        @delegate
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
woople-theme-0.6.17 app/presenters/woople_theme/reports/personal_report_presenter.rb
woople-theme-0.6.14 app/presenters/woople_theme/reports/personal_report_presenter.rb
woople-theme-0.6.13 app/presenters/woople_theme/reports/personal_report_presenter.rb
woople-theme-0.6.12 app/presenters/woople_theme/reports/personal_report_presenter.rb