Module: Util

Instance Method Summary collapse

Instance Method Details

#define_attributes(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/predicsis_ml_sdk/util.rb', line 13

def define_attributes(data)
  data.each do |k, v|
    if k.eql?('error')
      self.class.class_eval { attr_accessor "#{k}" }
      send("#{k}=", v)
    elsif v.is_a?(Hash)
      v.delete('id')
      define_attributes(v)
    else
      self.class.class_eval { attr_accessor "#{k}" }
      send("#{k}=", v)
    end
  end
end

#with_captured_consoleObject



2
3
4
5
6
7
8
9
10
11
# File 'lib/predicsis_ml_sdk/util.rb', line 2

def with_captured_console
  old_stdout = $stdout
  old_stderr = $stderr
  $stdout = $stderr = StringIO.new('', 'w')
  yield
  $stdout.string
ensure
  $stdout = old_stdout
  $stderr = old_stderr
end