<commit_before>require_relative '../../domain/modules/common/invariant'
require_relative '../../domain/modules/common/hash_init'

class Node

  include Invariant
  include HashInit

  attr_reader :name


  def attach_condition(condition)
    conditions.push(condition)
  end

  def conditions
    if @conditions.is_a? Array
      @conditions
    else
      @conditions = Array.new
      @conditions
    end
  end

  def edges
    if @edges.is_a? Array
      @edges
    else
      @edges = Array.new
      @edges
    end
  end

  def incoming_edges
    edges.select{|e| e.to == self}
  end

  def outgoing_edges
    edges.select{|e| e.from == self}
  end

  def attach_edge(edge)
    edges.push(edge)
  end

  def unattach_edge(edge)
    if edges.include?(edge)
      edges.pop(edge)
    else
      raise RuntimeError, "This #{self.class} does not include this #{edge.class}"
    end

  end

  def typed?
    !untyped?
  end

  def untyped?
    types.empty?
  end

  def attach_trigger(trig)
    triggers.push(trig+[true])
  end

  def triggers
    if @triggers.is_a? Array
      @triggers
    else
      @triggers = Array.new
      @triggers
    end
  end

  def clear_triggers
    triggers.each do |t|
      t[2]=true
    end
  end

  def trigger!
    triggers.each do |n|
      if (n[0].is_a? Proc) && n[2]
        if n[0].call
          n[2]=false
          n[1].stage!
        end
      elsif n[0] && n[2]
        n[2]=false
        n[1].stage!
      end
    end
  end

  def enabled?
    res=true
    conditions.each do |cond|
      if cond.is_a? Proc
        res=res && cond.call
      elsif cond === false
        return false
      elsif cond === true
        # do nothing
      end
    end
    res
  end<commit_msg>Make things more explicit.<commit_after>require_relative '../../domain/modules/common/invariant'
require_relative '../../domain/modules/common/hash_init'

class Node

  include Invariant
  include HashInit

  attr_reader :name


  def attach_condition(condition)
    conditions.push(condition)
  end

  def conditions
    if @conditions.is_a? Array
      @conditions
    else
      @conditions = Array.new
      @conditions
    end
  end

  def edges
    if @edges.is_a? Array
      @edges
    else
      @edges = Array.new
      @edges
    end
  end

  def incoming_edges
    edges.select{|e| e.to == self}
  end

  def outgoing_edges
    edges.select{|e| e.from == self}
  end

  def attach_edge(edge)
    edges.push(edge)
  end

  def attach_edge!(edge)
    attach_edge(edge)
    self
  end

  def detach_edge(edge)
    if edges.include?(edge)
      edges.pop(edge)
    else
      raise RuntimeError, "This #{self.class} does not include this #{edge.class}"
    end
  end

  def detach_edge!(edge)
    detach_edge(edge)
    self
  end

  def typed?
    !untyped?
  end

  def untyped?
    types.empty?
  end

  def attach_trigger(trig)
    triggers.push(trig+[true])
  end

  def triggers
    if @triggers.is_a? Array
      @triggers
    else
      @triggers = Array.new
      @triggers
    end
  end

  def clear_triggers
    triggers.each do |t|
      t[2]=true
    end
  end

  def fire_triggers!
    triggers.each do |n|
      if (n[0].is_a? Proc) && n[2]
        if n[0].call
          n[2]=false
          n[1].trigger!
        end
      elsif n[0] && n[2]
        n[2]=false
        n[1].trigger!
      end
    end
  end

  def enabled?
    res=true
    conditions.each do |cond|
      if cond.is_a? Proc
        res=res && cond.call
      elsif cond === false
        return false
      elsif cond === true
        # do nothing
      end
    end
    res
  end
{'fraction_non_alphanumeric': 0.09821925431274346, 'fraction_numerical': 0.005564830272676683, 'mean_word_length': 1.966171617161716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '470232', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1216, 'n_words': 316}