Sha256: 267bf18b0807a147f080b5445116b1b6d82c3288b0792b8ce78987b4922c899b

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  module Flow
    class State

      include Comparable

      attr_accessor :name, :events, :meta, :on_entry, :on_exit
      attr_reader :spec

      def initialize(name, spec, meta = {})
        @name, @spec, @events, @meta = name, spec, EventCollection.new, meta
      end

      def draw(graph)
        defaults = {
          :label => to_s,
          :width => '1',
          :height => '1',
          :shape => 'ellipse'
        }

        node = graph.add_nodes(to_s, defaults.merge(meta))

        # Add open arrow for initial state
        # graph.add_edge(graph.add_node('starting_state', :shape => 'point'), node) if initial?

        node
      end

      def <=>(other_state)
        states = spec.states.keys
        raise ArgumentError, "state `#{other_state}' does not exist" unless states.include?(other_state.to_sym)
        states.index(self.to_sym) <=> states.index(other_state.to_sym)
      end

      def to_s
        "#{name}"
      end

      def to_sym
        name.to_sym
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stealth-0.9.8 lib/stealth/flow/state.rb
stealth-0.9.7 lib/stealth/flow/state.rb
stealth-0.9.6 lib/stealth/flow/state.rb
stealth-0.9.5 lib/stealth/flow/state.rb
stealth-0.9.4 lib/stealth/flow/state.rb
stealth-0.9.3 lib/stealth/flow/state.rb
stealth-0.9.2 lib/stealth/flow/state.rb
stealth-0.9.1 lib/stealth/flow/state.rb