Sha256: 1736144c4865bb0f2938c6f351440e96e870d8eb85fb8a79eaa9858d9b6fbc3f

Contents?: true

Size: 1.89 KB

Versions: 18

Compression:

Stored size: 1.89 KB

Contents

module Parliament
  module Grom
    module Decorator
      # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Parliaments
      module ParliamentPeriod
        include Helpers::DateHelper

        # Alias parliamentPeriodStartDate with fallback.
        #
        # @return [DateTime, nil] the start date of the Grom::Node or nil.
        def start_date
          @start_date ||= respond_to?(:parliamentPeriodStartDate) ? DateTime.parse(parliamentPeriodStartDate) : nil
        end

        # Alias parliamentPeriodEndDate with fallback.
        #
        # @return [DateTime, nil] the end date of the Grom::Node or nil.
        def end_date
          @end_date ||= respond_to?(:parliamentPeriodEndDate) ? DateTime.parse(parliamentPeriodEndDate) : nil
        end

        # Alias parliamentPeriodNumber with fallback.
        #
        # @return [Integer, nil] the incremented number of the parliament
        def number
          @number ||= respond_to?(:parliamentPeriodNumber) ? parliamentPeriodNumber.to_i : nil
        end

        # Checks whether ParliamentPeriod has a next Parliament
        #
        # @return [true, false]
        def next_parliament?
          respond_to?(:parliamentPeriodHasImmediatelyFollowingParliamentPeriod)
        end

        # Checks whether ParliamentPeriod has a previous Parliament
        #
        # @return [true, false]
        def previous_parliament?
          respond_to?(:parliamentPeriodHasImmediatelyPreviousParliamentPeriod)
        end

        # Checks if Grom::Node is current - ie. it has a start date in the past or today and an end date which is nil, today or in the future.
        #
        # @return [Boolean] a boolean depending on whether or not the Grom::Node is current.
        def current?
          (!start_date.nil? && start_date <= Date.today) && (end_date.nil? || end_date >= Date.today)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
parliament-grom-decorators-0.10.1 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.10.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.9.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.8.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.7.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.6.1 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.6.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.4.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.3.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.8 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.7 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.6.pre lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.5.pre lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.4.pre lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.3 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.1 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.2.0 lib/parliament/grom/decorator/parliaments.rb
parliament-grom-decorators-0.1.8 lib/parliament/grom/decorator/parliaments.rb