Create Legislation Process Phase and Publication classes to enclose enabled?/started?/open? logic

This commit is contained in:
Bertocq
2017-06-13 19:52:28 +02:00
parent 0c27f1ffde
commit edee908fc1
2 changed files with 43 additions and 0 deletions

View File

@@ -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

View File

@@ -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