Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
mdt.rb - command.rb

command.rb

Caricato da:
Scarica il programma completo

  1. #!/usr/bin/env ruby
  2.  
  3. class Filter
  4.         attr_accessor   :toSub, :subbed
  5.         def initialize(toSub = "", subbed = "")
  6.                 @toSub = toSub
  7.                 @subbed = subbed
  8.         end
  9.         def filter(str)
  10.                 str.gsub!(@toSub, @subbed)
  11.         end
  12.         def Filter.filter(str, toSub, subbed)
  13.                 return str.gsub!(toSub, subbed)
  14.         end
  15. end
  16.  
  17. class Logger
  18.         attr_accessor   :filter, :quiteFlag
  19.         def initialize
  20.                 @logA = []
  21.                 @filter = nil
  22.                 @quiteFlag = false
  23.         end
  24.         def addLog(io)
  25.                 raise ParameterError.new if !io.is_a? IO
  26.                 @logA << io
  27.         end
  28.         def print(str)
  29.                 return if @quiteFlag
  30.                 str = str.to_s
  31.                 @filter.filter(str) if !@filter.nil?
  32.                 @logA.each do |io|
  33.                         io.print str
  34.                 end
  35.         end
  36.         def puts(str)
  37.                 return if @quiteFlag
  38.                 str = str.to_s
  39.                 @filter.filter(str) if !@filter.nil?
  40.                 @logA.each do |io|
  41.                         io.puts str
  42.                 end
  43.         end
  44.         def closeAll
  45.                 @logA.each {|l| l.close if (l != $stdout) && (l != $stderr)}
  46.         end
  47.         def Logger.print(str)
  48.                 $stdout.print str.to_s
  49.         end
  50.         def Logger.puts(str)
  51.                 $stdout.puts str.to_s
  52.         end
  53.         def Logger.f_puts(filter, str)
  54.                 str = str.to_s
  55.                 str.gsub! filter(toSub, filter.subbed)
  56.                 $stdout.puts str
  57.         end
  58.         def Logger.f_print(filter, str)
  59.                 str = str.to_s
  60.                 str.gsub! filter(toSub, filter.subbed)
  61.                 $stdout.print str
  62.         end
  63. end
  64.  
  65. class Console
  66.         def initialize(io)
  67.                 raise ParameterError.new if !io.kind_of? IO
  68.                 @io = io
  69.         end
  70.         def gets
  71.                 return @io.readline
  72.         end
  73. end