Class: GovukWebBanners::RecruitmentBanner
- Inherits:
-
Object
- Object
- GovukWebBanners::RecruitmentBanner
- Defined in:
- lib/govuk_web_banners/recruitment_banner.rb
Constant Summary collapse
- BANNER_CONFIG_FILE =
"../../config/govuk_web_banners/recruitment_banners.yml".freeze
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#page_paths ⇒ Object
readonly
Returns the value of attribute page_paths.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#suggestion_link_text ⇒ Object
readonly
Returns the value of attribute suggestion_link_text.
-
#suggestion_text ⇒ Object
readonly
Returns the value of attribute suggestion_text.
-
#survey_url ⇒ Object
readonly
Returns the value of attribute survey_url.
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
NB: .between? is inclusive.
-
#initialize(attributes:) ⇒ RecruitmentBanner
constructor
A new instance of RecruitmentBanner.
Constructor Details
#initialize(attributes:) ⇒ RecruitmentBanner
Returns a new instance of RecruitmentBanner.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 23 def initialize(attributes:) @name = attributes["name"] @suggestion_text = attributes["suggestion_text"] @suggestion_link_text = attributes["suggestion_link_text"] @survey_url = attributes["survey_url"] @page_paths = attributes["page_paths"] @start_date = attributes["start_date"] ? ActiveSupport::TimeZone[GovukWebBanners::TIME_ZONE].parse(attributes["start_date"]) : Time.at(0) @end_date = attributes["end_date"] ? ActiveSupport::TimeZone[GovukWebBanners::TIME_ZONE].parse(attributes["end_date"]) : Time.now + 10.years @image = attributes["image"] end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def end_date @end_date end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def image @image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def name @name end |
#page_paths ⇒ Object (readonly)
Returns the value of attribute page_paths.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def page_paths @page_paths end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def start_date @start_date end |
#suggestion_link_text ⇒ Object (readonly)
Returns the value of attribute suggestion_link_text.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def suggestion_link_text @suggestion_link_text end |
#suggestion_text ⇒ Object (readonly)
Returns the value of attribute suggestion_text.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def suggestion_text @suggestion_text end |
#survey_url ⇒ Object (readonly)
Returns the value of attribute survey_url.
21 22 23 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 21 def survey_url @survey_url end |
Class Method Details
.active_banners ⇒ Object
11 12 13 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 11 def self. .select(&:active?) end |
.all_banners ⇒ Object
15 16 17 18 19 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 15 def self. = Rails.root.join(__dir__, BANNER_CONFIG_FILE) = YAML.load_file() ["banners"].map { |attributes| RecruitmentBanner.new(attributes:) } end |
.for_path(path) ⇒ Object
5 6 7 8 9 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 5 def self.for_path(path) .find do || return if .page_paths.include?(path) end end |
Instance Method Details
#active? ⇒ Boolean
NB: .between? is inclusive. To make it exclude the end date, we set the end range as
1 second earlier.
36 37 38 |
# File 'lib/govuk_web_banners/recruitment_banner.rb', line 36 def active? Time.zone.now.between?(start_date, end_date - 1.second) end |