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 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Trim

Returns a new instance of Trim.



37
38
39
# File 'lib/judges/commands/trim.rb', line 37

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object

Run it (it is supposed to be called by the bin/judges script.

Parameters:

  • opts (Hash)

    Command line options (start with ‘–’)

  • args (Array)

    List of command line arguments



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/judges/commands/trim.rb', line 44

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