Class: Judges::Trim

Inherits:
Object show all
Defined in:
lib/judges/commands/trim.rb

Overview

The trim command.

This class is instantiated by the bin/judge command line interface. You are not supposed to instantiate it yourself.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Trim

Initialize.

Parameters:

  • loog (Loog)

    Logging facility



22
23
24
# File 'lib/judges/commands/trim.rb', line 22

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object

Run the trim command (called by the bin/judges script).

Parameters:

  • opts (Hash)

    Command line options (start with ‘–’)

  • args (Array)

    List of command line arguments

Raises:

  • (RuntimeError)

    If not exactly one argument provided



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/judges/commands/trim.rb', line 30

def run(opts, args)
  raise 'Exactly one argument required' unless args.size == 1
  impex = Judges::Impex.new(@loog, args[0])
  fb = impex.import
  elapsed(@loog, level: Logger::INFO) do
    deleted = fb.query(opts['query']).delete!
    throw :'⚠️ No facts deleted' if deleted.zero?
    impex.export(fb)
    throw :"👍 #{deleted} fact(s) deleted"
  end
end