Sha256: d5d1a11ea4ddde30fda22c04e6f80cf9b160f84a739e3995c35db92297173d6d

Contents?: true

Size: 1.57 KB

Versions: 32

Compression:

Stored size: 1.57 KB

Contents

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

module WoopleTheme
  module Reports
    class ActivityReportPresenter < 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

32 entries across 32 versions & 1 rubygems

Version Path
woople-theme-0.10.0 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.9.0 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.19 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.18 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.17 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.16 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.15 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.14 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.13 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.12 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.11 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.10 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.9 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.8 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.7 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.6 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.5 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.4 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.3 app/presenters/woople_theme/reports/activity_report_presenter.rb
woople-theme-0.8.2 app/presenters/woople_theme/reports/activity_report_presenter.rb