Sha256: f296fc6eca87f8e08244c2bc65e116820a34bb3e3b77262789b0bdd673361f93

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

module Pione
  module Model
    # TicketExpr is a ticket expression as alternative input or output
    # conditions of rules for serial processing.
    #
    # @example Serial process of rule A and B by tickets in PIONE flow rule
    #   Rule Main
    #     input '*.in'
    #     output '*.out'
    #   Flow
    #     rule A ==> <T>
    #     <T> ==> rule B
    #   End
    class TicketExpr < Element
      # ticket name
      attr_reader :name

      # @param name [String]
      #   ticket name
      def initialize(name)
        @name = name
      end

      def eval(vtable)
        self
      end

      def include_variable?
        false
      end

      def textize
        "<%s>" % [@names]
      end

      def ==(other)
        return false unless other.kind_of?(self.class)
        @name == other.name
      end
      alias :eql? :"=="

      def hash
        @name.hash
      end
    end

    class TicketExprSequence < OrdinalSequence
      set_pione_model_type TypeTicketExpr
      set_element_class TicketExpr
      set_shortname "TSeq"

      # Get ticket names of all elements in the sequence.
      #
      # @return [Array<String>]
      #   ticket names
      def names
        @elements.map {|elt| elt.name}
      end
    end

    TypeTicketExpr.instance_eval do
      define_pione_method("==>", [TypeRuleExpr], TypeRuleExpr) do |vtable, rec, other|
        other.add_input_ticket_expr(rec)
      end

      define_pione_method("as_string", [], TypeString) do |vtable, rec|
        rec.textize
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pione-0.2.2 lib/pione/model/ticket-expr.rb
pione-0.2.1 lib/pione/model/ticket-expr.rb
pione-0.2.0 lib/pione/model/ticket-expr.rb