Module: Parliament::Grom::Decorator::ParliamentPeriod

Includes:
Helpers::DateHelper
Defined in:
lib/parliament/grom/decorator/parliaments.rb

Overview

Decorator namespace for Grom::Node instances with type: id.parliament.uk/schema/Parliaments

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helpers::DateHelper

#date_range

Instance Method Details

#current?Boolean

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.

Returns:

  • (Boolean)

    a boolean depending on whether or not the Grom::Node is current.

Since:

  • 0.1.0



46
47
48
# File 'lib/parliament/grom/decorator/parliaments.rb', line 46

def current?
  (!start_date.nil? && start_date <= Date.today) && (end_date.nil? || end_date >= Date.today)
end

#end_dateDateTime?

Alias parliamentPeriodEndDate with fallback.

Returns:

  • (DateTime, nil)

    the end date of the Grom::Node or nil.

Since:

  • 0.1.0



18
19
20
# File 'lib/parliament/grom/decorator/parliaments.rb', line 18

def end_date
  @end_date ||= respond_to?(:parliamentPeriodEndDate) ? DateTime.parse(parliamentPeriodEndDate) : nil
end

#next_parliament?true, false

Checks whether ParliamentPeriod has a next Parliament

Returns:

  • (true, false)

Since:

  • 0.1.0



32
33
34
# File 'lib/parliament/grom/decorator/parliaments.rb', line 32

def next_parliament?
  respond_to?(:parliamentPeriodHasImmediatelyFollowingParliamentPeriod)
end

#numberInteger?

Alias parliamentPeriodNumber with fallback.

Returns:

  • (Integer, nil)

    the incremented number of the parliament

Since:

  • 0.1.0



25
26
27
# File 'lib/parliament/grom/decorator/parliaments.rb', line 25

def number
  @number ||= respond_to?(:parliamentPeriodNumber) ? parliamentPeriodNumber.to_i : nil
end

#previous_parliament?true, false

Checks whether ParliamentPeriod has a previous Parliament

Returns:

  • (true, false)

Since:

  • 0.1.0



39
40
41
# File 'lib/parliament/grom/decorator/parliaments.rb', line 39

def previous_parliament?
  respond_to?(:parliamentPeriodHasImmediatelyPreviousParliamentPeriod)
end

#start_dateDateTime?

Alias parliamentPeriodStartDate with fallback.

Returns:

  • (DateTime, nil)

    the start date of the Grom::Node or nil.

Since:

  • 0.1.0



11
12
13
# File 'lib/parliament/grom/decorator/parliaments.rb', line 11

def start_date
  @start_date ||= respond_to?(:parliamentPeriodStartDate) ? DateTime.parse(parliamentPeriodStartDate) : nil
end