Class: Judges::Print
- Inherits:
-
Object
- Object
- Judges::Print
- Defined in:
- lib/judges/commands/print.rb
Overview
Update.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Print
constructor
A new instance of Print.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(loog) ⇒ Print
Returns a new instance of Print.
33 34 35 |
# File 'lib/judges/commands/print.rb', line 33 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/judges/commands/print.rb', line 37 def run(opts, args) raise 'Exactly two arguments required' unless args.size == 2 f = args[0] raise "The file is absent: #{f}" unless File.exist?(f) o = args[1] fb = Factbase.new fb.import(File.read(f)) @loog.info("Factbase imported from #{f} (#{File.size(f)} bytes)") FileUtils.mkdir_p(File.dirname(o)) output = case opts[:format].downcase when 'yaml' fb.to_yaml when 'json' fb.to_json when 'xml' fb.to_xml end File.write(o, output) @loog.info("Factbase printed to #{o} (#{File.size(o)} bytes)") end |