Sha256: 8c070fff1604b74f0927096cceefc49b5876e04418c9077cde10e3932901a12b

Contents?: true

Size: 997 Bytes

Versions: 11

Compression:

Stored size: 997 Bytes

Contents

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

11 entries across 11 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc11 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc10 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc9 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc8 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc7 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc6 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc5 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc4 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc3 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.rc1 app/presenters/renalware/pd/training_duration_presenter.rb
renalware-core-2.0.0.pre.beta12 app/presenters/renalware/pd/training_duration_presenter.rb