Sha256: bb538471bed707e26117db9239e59a1590801d3d6d8cc432d7802cac2ce45a1d

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require_relative 'term'
require_relative 'freshness'

module MiniKraken
  module Core
    # An composite term is an Minikraken term that can be
    # decomposed into simpler MiniKraken data value(s).
    class CompositeTerm < Term
      # Abstract method (to override). Return the child terms.
      # @return [Array<Term>]
      def children
        raise NotImplementedError, 'This method must re-defined in subclass(es).'
      end

      # A composite term is fresh when all its members are nil or all non-nil members
      # are all fresh
      # A composite term is bound when it is not fresh and not ground
      # A composite term is a ground term when all its non-nil members are ground.
      # @param _env [Vocabulary]
      # @return [Freshness]
      def freshness(_env)
         env.freshness_composite(self)
      end

      # @param env [Environment]
      # @return [Boolean]
      def fresh?(env)
        env.fresh_value?(self)
      end

      # A composite is ground if all its children are ground
      def ground?(anEnv)
        children.all? do |child|
          child.nil? || child.ground?(anEnv)
        end
      end
    end # class
  end # module
end # module

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mini_kraken-0.2.03 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.2.02 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.2.01 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.2.00 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.13 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.12 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.11 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.10 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.09 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.08 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.07 lib/mini_kraken/core/composite_term.rb
mini_kraken-0.1.06 lib/mini_kraken/core/composite_term.rb