<commit_before>class AngryMob
  class Target
    class Call
      attr_reader :args, :klass, :actions
      attr_accessor :target

      def initialize(klass,*args)
        @klass = klass
        @args = extract_args(args)
        validate_actions!
      end

      def instance_key
        klass.instance_key(args)
      end

      def merge_defaults(defaults)
        args.reverse_deep_merge!(defaults)
      end

      def call(act)
        target.act = act
        puts "target=#{target}"
        target.noticing_changes(args) {
          actions.each {|action|
            target.send(action.tapp(:action))
          }
        }
      end

      def nickname
        klass.nickname
      end

      def validate_actions!
        @actions = [ args.actions, args.action ].norm.map{|s| s.to_s}

        extras = actions - klass.actions
        raise(ArgumentError, "#{nickname}() unknown actions #{extras.inspect}") unless extras.empty? || extras == ['nothing']

        actions << klass.default_action_name if actions.empty?

        if actions.norm.empty?
          raise ArgumentError, "#{klass.nickname}() no actions selected, and no default action defined"
        end

        puts "actions validated"
        actions.tapp
      end


      def extract_args(args)
        case args.size
        when 0,1
          new_args = AngryHash.new
          new_args.default_object = args[0]

        when 2
          new_args = AngryHash.__convert_without_dup(args[1])
          new_args.default_object = args[0]

        else
          raise ArgumentError, "usage: #{klass.nickname}(default_object, [ :optional_hash_of => opts ])"
        end

        new_args
      end
    end
  end
end<commit_msg>use all_actions, smarter arg parsing.<commit_after>class AngryMob
  class Target
    class Call
      attr_reader :args, :klass, :actions
      attr_accessor :target

      def initialize(klass,*args)
        @klass = klass
        @args = extract_args(args)
        validate_actions!
      end

      def instance_key
        klass.instance_key(args)
      end

      def merge_defaults(defaults)
        args.reverse_deep_merge!(defaults)
      end

      def call(act)
        target.act = act
        target.noticing_changes(args) {
          actions.each {|action|
            target.send(action)
          }
        }
      end

      def nickname
        klass.nickname
      end

      def validate_actions!
        @actions = [ args.actions, args.action ].norm.map{|s| s.to_s}

        #klass.tapp
        #actions.tapp('requested actions')
        #klass.default_action_name.tapp('default action')

        extras = actions - klass.all_actions
        raise(ArgumentError, "#{nickname}() unknown actions #{extras.inspect}") unless extras.empty? || extras == ['nothing']

        actions << klass.default_action_name if actions.empty?

        if actions.norm.empty?
          raise ArgumentError, "#{klass.nickname}() no actions selected, and no default action defined"
        end

        actions.tapp('selected action')
      end


      def extract_args(args)
        case args.size
        when 0,1
          if Hash === args[0]
            new_args = AngryHash.__convert_without_dup(args[0])
            new_args.default_object = new_args
          else
            new_args = AngryHash.new
            new_args.default_object = args[0]
          end

        when 2
          new_args = AngryHash.__convert_without_dup(args[1])
          new_args.default_object = args[0]

        else
          raise ArgumentError, "usage: #{klass.nickname}(default_object, [ :optional_hash_of => opts ])"
        end

        new_args
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09110747408619749, 'fraction_numerical': 0.0038188761593016913, 'mean_word_length': 1.983726606997559, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5189164', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1064, 'n_words': 241}