/procedures/meta/comments

The main parsing code and the individual parsing rules for source steps types are packaged into separate files.

We require the main parsing code to be loaded ...

 3 require "#{Rails.root}/lib/parsing/parse"

... together with the code for parsing specific step types ...

 6 require "#{Rails.root}/lib/parsing/and_step"
 7 require "#{Rails.root}/lib/parsing/business_step"
 8 require "#{Rails.root}/lib/parsing/decision_step"
 9 require "#{Rails.root}/lib/parsing/not_step"
 10 require "#{Rails.root}/lib/parsing/or_step"
 11 require "#{Rails.root}/lib/parsing/sum_step"
 12 require "#{Rails.root}/lib/parsing/increment_step"
 13 require "#{Rails.root}/lib/parsing/equals_step"
 14 require "#{Rails.root}/lib/parsing/summation_step"

... and the code for storing route attributes, determining route currency and assigning potential step states.

 17 require "#{Rails.root}/lib/parsing/route_hash"
 18 require "#{Rails.root}/lib/parsing/step_hash"
 19 require "#{Rails.root}/lib/parsing/route_currency"
 20 require "#{Rails.root}/lib/parsing/assign_potential_business_step_state"

Work package controller

 23 class WorkPackageController < ApplicationController

We include code for the main parsing rules ...

 26   include PARSE

... together with code for the different styles of parsing according to the type of the source step ...

 29   include PARSE_BUSINESS_STEP
 30   include PARSE_DECISION_STEP
 31   include PARSE_NOT_STEP
 32   include PARSE_AND_STEP
 33   include PARSE_OR_STEP
 34   include PARSE_SUM_STEP
 35   include PARSE_INCREMENT_STEP
 36   include PARSE_EQUALS_STEP
 37   include PARSE_SUMMATION_STEP

... and the code for storing route attributes, determining route currency and assigning potential step states.

 40   include PARSE_ROUTE_HASH
 41   include PARSE_STEP_HASH
 42   include PARSE_ROUTE_CURRENCY
 43   include PARSE_ASSIGN_POTENTIAL_BUSINESS_STEP_STATE
 45   def show
 46     parse
 48     @business_items_that_have_happened = @work_package.business_items_that_have_happened
 49     @business_items_that_are_scheduled_to_happen = @work_package.business_items_that_are_scheduled_to_happen
 50     @business_items_unknown = @work_package.business_items_unknown
 51   end
 53   def log
 54     parse
 55   end

This method attempts to parse a work package subject to a procedure.

By taking actualised and non-actualised business steps and parsing the logical procedure map, we aim to determine business steps that may happen, should happen or should not happen in the future.

 59   def parse

We get the work package we're attempting to parse.

 62     work_package = params[:work_package]
 63     @work_package = WorkPackage.find( work_package )

We get the procedure the work package is subject to.

The procedure is stored as an instance variable because we want to report from it later.

 67     @procedure = @work_package.parliamentary_procedure

We set the parse pass count to zero.

The parse pass count will be incremented every time we attempt to parse a route.

The parse pass count is created as an instance variable because we want to increment on each parse pass and report from it later.

 72     @parse_pass_count = 0

We create an array to log the parsing.

The log is created as an instance variable because we want to write to it and report from it later.

 76     @parse_log = []

We write to the log, explaining what we're attempting to do.

 79     @parse_log << "Attempting to parse work package #{@work_package.id}, subject to the #{@procedure.name.downcase} procedure."

Having successfully parsed a route to a business step, we can determine the potential state of that business step. The potential state of a business state may be caused to be actualised, allowed to be actualised, not yet actualisable or not now actualisable.

We create a set of arrays to store the target business steps of the routes we successfully parse - each array being named according to the potential state of the target step.

These are created as instance variables because we want to write to them and report from them later.

 84     @caused_steps = []
 85     @allowed_steps = []
 86     @disallowed_as_yet_steps = []
 87     @disallowed_now_steps = []

We initialise a hash of additional route attributes: these are attributes used only during the parsing process.

 90     initialise_route_hash( @work_package )

We initialise a hash of steps keyed off the step ID together with a hash of IDs of outbound routes from a step and a hash of IDs of inbound routes to a step, also keyed off the step ID.

 93     initialise_step_hashes( @procedure )

We get an array of the start steps in the procedure.

 96     start_steps = @procedure.start_steps

We loop through the start steps in the procedure ...

 99     start_steps.each do |step|

... then loop through the outbound routes of each start step ...

 102       step_outbound_routes( step.id ).each do |route_id|

... and parse each of those routes, passing in the ID of the route.

 105         parse_route_with_id( route_id )
 106       end
 107     end
 108   end
 109 end