Class: ContentBlockTools::Presenters::FieldPresenters::TimePeriod::DateRangePresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
lib/content_block_tools/presenters/field_presenters/time_period/date_range_presenter.rb

Constant Summary

Constants inherited from BasePresenter

BasePresenter::BASE_TAG_TYPE

Instance Attribute Summary

Attributes inherited from BasePresenter

#field

Instance Method Summary collapse

Constructor Details

#initialize(field, **args) ⇒ DateRangePresenter

Returns a new instance of DateRangePresenter.



8
9
10
11
# File 'lib/content_block_tools/presenters/field_presenters/time_period/date_range_presenter.rb', line 8

def initialize(field, **args)
  super
  @normalised_date_range = normalise_date_range
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
# File 'lib/content_block_tools/presenters/field_presenters/time_period/date_range_presenter.rb', line 13

def render
  return unless start_date.present? && end_date.present?

  "#{start_date} to #{end_date}"
rescue NormalisedDateRange::ParseError => e
  raise TimePeriodPresenterError, "Not a valid date range: #{field} (#{e.message})"
end