Top Level Namespace

Defined Under Namespace

Modules: Calamum

Instance Method Summary collapse

Instance Method Details

#pj(json, indent = ' ') ⇒ String

Returns a formatted JSON string.

Parameters:

  • json (String)

    JSON string to format

  • indent (String) (defaults to: ' ')

    indent that used in formatting

Returns:

  • (String)

    prettier form of the given JSON string



6
7
8
9
# File 'lib/calamum/helpers.rb', line 6

def pj(json, indent = ' ')
  require 'json'
  JSON.pretty_generate(json, :indent => indent * 4).gsub!(/\n/, '<br/>')
end

#puts_error(msg) ⇒ Object

Output error message to console.

Parameters:

  • msg (String)

    message to output



28
29
30
31
# File 'lib/calamum/helpers.rb', line 28

def puts_error(msg)
  $stderr.puts "\e[31m[ERROR] #{msg}\e[0m" if Calamum::Config[:debug]
  exit(1)
end

#puts_info(msg) ⇒ Object

Output info message to console.

Parameters:

  • msg (String)

    message to output



14
15
16
# File 'lib/calamum/helpers.rb', line 14

def puts_info(msg)
  $stdout.puts "\e[32m[INFO] #{msg}\e[0m" if Calamum::Config[:debug]
end

#puts_warning(msg) ⇒ Object

Output warning message to console.

Parameters:

  • msg (String)

    message to output



21
22
23
# File 'lib/calamum/helpers.rb', line 21

def puts_warning(msg)
  $stdout.puts "\e[33m[WARNING] #{msg}\e[0m" if Calamum::Config[:debug]
end