Sha256: d207fffa0f257a3ac29b3b9c5fb436014c6e52d98bf326faa8a6bb5b05cb3600

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 DeliveryIntervalPresenter
      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.delivery_intervals.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.0.104 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.103 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.102 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.101 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.100 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.99 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.98 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.97 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.96 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.95 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.94 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.93 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.92 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.91 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.90 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.89 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.88 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.87 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.86 app/presenters/renalware/pd/delivery_interval_presenter.rb
renalware-core-2.0.85 app/presenters/renalware/pd/delivery_interval_presenter.rb