Class: Htk::Base
- Inherits:
-
Object
- Object
- Htk::Base
- Defined in:
- lib/Htk/utils.rb
Instance Method Summary collapse
-
#fdebug(text, file_path = DEFAULT_FILE_PATH) ⇒ Object
(also: #fdb)
Dumps the given text to the given file.
-
#fdebug_json(obj, file_path = DEFAULT_FILE_PATH) ⇒ Object
(also: #fdb_json)
Dumps given object to given file as JSON.
- #slack_debug(text) ⇒ Object (also: #sdb)
Instance Method Details
#fdebug(text, file_path = DEFAULT_FILE_PATH) ⇒ Object Also known as: fdb
Dumps the given text to the given file. If file_path omited, uses ‘DEFAULT_FILE_PATH’
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/Htk/utils.rb', line 42 def fdebug(text, file_path=DEFAULT_FILE_PATH) counter = ::Htk::FDebugCounter.instance counter.increment now = ::DateTime.now now_str = now.strftime('%Y-%m-%d %H:%I:%S') dirname = File.dirname(file_path) unless File.directory?(dirname) FileUtils.mkdir_p(dirname) end open(file_path, 'a') { |f| f << ">>>>>>>>>> FDEBUG #{counter.count} #{now_str} <<<<<<<<<<\n" f << text + "\n" f << ">>>>>>>>>> FDEBUG #{counter.count} #{now_str} <<<<<<<<<<\n" } end |
#fdebug_json(obj, file_path = DEFAULT_FILE_PATH) ⇒ Object Also known as: fdb_json
Dumps given object to given file as JSON. If file_path omited, default path is ‘DEFAULT_FILE_PATH’
65 66 67 68 |
# File 'lib/Htk/utils.rb', line 65 def fdebug_json(obj, file_path=DEFAULT_FILE_PATH) data = obj.to_json fdebug(JSON.pretty_generate(data), file_path) end |
#slack_debug(text) ⇒ Object Also known as: sdb
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Htk/utils.rb', line 26 def slack_debug(text) conn = ::Htk::Apis::SlackDebug.connection response = conn.post('') do |req| req.headers['Accept'] = 'application/json' req.headers['Content-Type'] = 'application/json' req.body = { 'text' => text, }.to_json end response.status end |