Sha256: e33ed499ef91f2f8f4cc9b331d57ad7ed9cd62d956426629511cc4287d3b5741

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

# lib/stair_master/concerns/getters.rb
##
##
##
module StairMaster
  module Concerns
    module Getters
      extend ActiveSupport::Concern

      private # -------------------------------------------

      def get_step_index_by_name(step_name)
        available_steps.find_index step_name
      end

      def get_step_name_by_index(step_index)
        available_steps[step_index]
      end

      def get_step_by_index(step_index)
        get_step_by_name available_steps[step_index]
      end

      def get_step_by_name(step_name)
        workflow_map.steps[step_name]
      end

      ## NEXT STEP ----------------------------------------
      def get_next_step_index
        on_last_step? ? nil : find_next_step_index
      end

      def find_next_step_index(step_index=nil)
        next_index  = step_index.nil? ? current_step_index.next : step_index.next
        step        = get_step_by_index next_index

        if step.nil?
          nil
        elsif step.skip?(self)
          if is_last_step?(step.key)
            return nil
          else
            find_next_step_index(next_index)
          end
        else
          next_index
        end
      end

      ## GET PREVIOIUS STEP INDEX -------------------------
      def get_previous_step_index(step_index=nil)
        on_first_step? ? nil : find_previous_step_index
      end

      def find_previous_step_index(step_index=nil)
        previous_index  = step_index.nil? ? current_step_index.pred : step_index.pred
        step            = get_step_by_index previous_index

        if step.nil?
          nil
        elsif step.skip?(self)
          if is_first_step?(step.key)
            return nil
          else
            find_previous_step_index(previous_index)
          end
        else
          previous_index
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stair_master-0.1.0 lib/stair_master/concerns/getters.rb
stair_master-0.0.3 lib/stair_master/concerns/getters.rb
stair_master-0.0.2 lib/stair_master/concerns/getters.rb