From edee908fc1ab565408d0f99043e99435fa7ea33d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 19:52:28 +0200 Subject: [PATCH] Create Legislation Process Phase and Publication classes to enclose enabled?/started?/open? logic --- app/models/legislation/process/phase.rb | 22 +++++++++++++++++++ app/models/legislation/process/publication.rb | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/models/legislation/process/phase.rb create mode 100644 app/models/legislation/process/publication.rb diff --git a/app/models/legislation/process/phase.rb b/app/models/legislation/process/phase.rb new file mode 100644 index 000000000..1b8482a9a --- /dev/null +++ b/app/models/legislation/process/phase.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class Legislation::Process::Phase + + def initialize(start_date, end_date) + @start_date = start_date + @end_date = end_date + end + + def enabled? + @start_date.present? && @end_date.present? + end + + def started? + enabled? && Date.current >= @start_date + end + + def open? + started? && Date.current <= @end_date + end + +end diff --git a/app/models/legislation/process/publication.rb b/app/models/legislation/process/publication.rb new file mode 100644 index 000000000..10110f0e7 --- /dev/null +++ b/app/models/legislation/process/publication.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Legislation::Process::Publication + + def initialize(publication_date) + @publication_date = publication_date + end + + def enabled? + @publication_date.present? + end + + def started? + enabled? && Date.current >= @publication_date + end + + def open? + started? + end + +end