Module: Parliament::Grom::Decorator::BusinessItem

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

Overview

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

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helpers::DateHelper

#date_range

Instance Method Details

#dateDate?

Alias businessItemDate with fallback.

Returns:

  • (Date, nil)

    a laying date or nil.

Since:

  • 0.1.0



31
32
33
# File 'lib/parliament/grom/decorator/business_item.rb', line 31

def date
  respond_to?(:businessItemDate) ? DateTime.parse(businessItemDate) : nil
end

#procedure_stepsArray

Alias businessItemHasProcedureStep with fallback.

Returns:

  • (Array, Array)

    an array of ProcedureStep Grom::Nodes of the Grom::Node or an empty array.

Since:

  • 0.1.0



10
11
12
# File 'lib/parliament/grom/decorator/business_item.rb', line 10

def procedure_steps
  respond_to?(:businessItemHasProcedureStep) ? businessItemHasProcedureStep : []
end

#shortest_distance_of_procedure_stepsInteger?

Finds, for each of the procedure steps belonging to a business item, the shortest distance from origin

Returns:

  • (Integer, nil)

    shortest distance of procedure steps from origin or nil.

Since:

  • 0.1.0



24
25
26
# File 'lib/parliament/grom/decorator/business_item.rb', line 24

def shortest_distance_of_procedure_steps
  sorted_procedure_steps_by_distance.first&.distance_from_origin
end

#sorted_procedure_steps_by_distanceArray

Each procedure step has a distance from origin

Returns:

  • (Array)

    an array of ProcedureStep Grom::Nodes sorted by distance from origin.

Since:

  • 0.1.0



17
18
19
# File 'lib/parliament/grom/decorator/business_item.rb', line 17

def sorted_procedure_steps_by_distance
  procedure_steps.sort_by(&:distance_from_origin)
end

Alias businessItemHasBusinessItemWebLink with fallback.

Returns:

  • (String, String)

    a web link to view business item Grom::Node or an empty string.

Since:

  • 0.1.0



38
39
40
# File 'lib/parliament/grom/decorator/business_item.rb', line 38

def weblink
  respond_to?(:businessItemHasBusinessItemWebLink) ? businessItemHasBusinessItemWebLink : ''
end