Sha256: f1eff81748f1dba4e484881f003fb4cd71e354a2cb98a70a6413802e90a46945

Contents?: true

Size: 1 KB

Versions: 158

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pd"

module Renalware
  module PD
    class TrainingDurationPresenter
      def initialize(duration)
        @interval = duration.present? ? parse_iso8601_duration(duration) : NullObject.instance
      end

      def to_s
        interval.to_formatted_s
      end

      # An array of delivery interval options derived from the PD configuration, and using an
      # iso8601 representation of the duration (eg "P4W" for 4 weeks), e.g.
      # [
      #  [
      #    "1 week", "P1W",
      #    "1 year", "P1Y",
      #    ...
      #  ]
      # ]
      # Note use Duration#to_formatted_s when rendering out a duration anywhere in the app.
      def self.dropdown_options
        PD.config.training_durations.map do |duration|
          [duration.to_formatted_s, duration.iso8601]
        end
      end

      private

      attr_reader :interval

      def parse_iso8601_duration(duration)
        ActiveSupport::Duration.parse(duration)
      end
    end
  end
end

Version data entries

158 entries across 158 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.1.0 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.167 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.166 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.165 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.164 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.163 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.162 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.161 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.160 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.159 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.158 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.157 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.156 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.155 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.153 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.152 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.151 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.149 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.148 app/presenters/renalware/pd/training_duration_presenter.rb