Class: GovukWebBanners::UpratingBanner
- Inherits:
-
Object
- Object
- GovukWebBanners::UpratingBanner
- Defined in:
- lib/govuk_web_banners/uprating_banner.rb
Constant Summary collapse
- BANNER_CONFIG_FILE =
"../../config/govuk_web_banners/uprating_banners.yml".freeze
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#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.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
NB: .between? is inclusive.
-
#initialize(attributes:) ⇒ UpratingBanner
constructor
A new instance of UpratingBanner.
Constructor Details
#initialize(attributes:) ⇒ UpratingBanner
Returns a new instance of UpratingBanner.
23 24 25 26 27 28 29 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 23 def initialize(attributes:) @name = attributes["name"] @text = attributes["text"] @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 end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
21 22 23 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 21 def end_date @end_date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/govuk_web_banners/uprating_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/uprating_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/uprating_banner.rb', line 21 def start_date @start_date end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
21 22 23 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 21 def text @text end |
Class Method Details
.active_banners ⇒ Object
11 12 13 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 11 def self. .select(&:active?) end |
.all_banners ⇒ Object
15 16 17 18 19 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 15 def self. = Rails.root.join(__dir__, BANNER_CONFIG_FILE) = YAML.load_file() ["banners"].map { |attributes| UpratingBanner.new(attributes:) } end |
.for_path(path) ⇒ Object
5 6 7 8 9 |
# File 'lib/govuk_web_banners/uprating_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.
33 34 35 |
# File 'lib/govuk_web_banners/uprating_banner.rb', line 33 def active? Time.zone.now.between?(start_date, end_date - 1.second) end |