Sha256: f24f4c486d8e4ca75abcc93930b1d8dbc5345db721318f9a013a33632f706a79

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

module Bmg
  module Operator
    include Relation

    def to_s
      str = "(#{self.class.name.split('::').last.downcase}\n"
      str << operands.map{|op| op.to_s.gsub(/^/m, "  ") }.join("\n")
      str << "\n"
      str << args.map{|a| a.to_s.gsub(/^/m, "  ") }.join("\n")
      str << ")"
      str
    end

    def inspect
      str = "(#{self.class.name.split('::').last.downcase}\n"
      str << operands.map{|op| op.inspect.gsub(/^/m, "  ") }.join("\n")
      str << "\n"
      str << args.map{|a| a.inspect.gsub(/^/m, "  ") }.join("\n")
      str << ")"
      str
    end

    module Unary
      include Operator

      attr_reader :type, :operand

      def _visit(parent, visitor)
        visitor.call(self, parent)
        operand._visit(self, visitor)
      end

      def operands
        [operand]
      end

    end

    module Binary
      include Operator

      attr_reader :type, :left, :right

      def _visit(parent, visitor)
        visitor.call(self, parent)
        left._visit(self, visitor)
        right._visit(self, visitor)
      end

      def operands
        [left, right]
      end
    end

    module Nary
      include Operator

      attr_reader :type, :operands

      def _visit(parent, visitor)
        visitor.call(self, parent)
        operands.each{|op| op._visit(self, visitor) }
      end
    end

  end
end
require_relative 'operator/allbut'
require_relative 'operator/autosummarize'
require_relative 'operator/autowrap'
require_relative 'operator/constants'
require_relative 'operator/extend'
require_relative 'operator/group'
require_relative 'operator/image'
require_relative 'operator/join'
require_relative 'operator/matching'
require_relative 'operator/page'
require_relative 'operator/project'
require_relative 'operator/rename'
require_relative 'operator/restrict'
require_relative 'operator/rxmatch'
require_relative 'operator/union'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bmg-0.11.0 lib/bmg/operator.rb