Module: Croupier

Defined in:
lib/croupier.rb,
lib/croupier/exceptions.rb,
lib/croupier/distribution.rb,
lib/croupier/cli/application.rb,
lib/croupier/distributions/normal.rb,
lib/croupier/distributions/uniform.rb,
lib/croupier/distributions/exponential.rb

Overview

The module defines a Croupier::CLI::Application and interacts with the user output console.

Defined Under Namespace

Modules: CLI, Distributions Classes: Distribution, Error, InputParamsError, InvalidOptionError

Constant Summary collapse

STDERR =
$stderr
STDOUT =
$stdout

Class Method Summary collapse

Class Method Details

.applicationObject

Current Croupier Application



19
20
21
# File 'lib/croupier.rb', line 19

def application
  @application ||= ::Croupier::CLI::Application.new
end

.application=(app) ⇒ Object

Set the current Croupier application object.



24
25
26
# File 'lib/croupier.rb', line 24

def application=(app)
  @application = app
end

.clear_line!Object

Clear current console line



53
54
55
# File 'lib/croupier.rb', line 53

def clear_line!
  self.write "\r"
end

.error_message(msg) ⇒ Object

Writes message to the error output



41
42
43
44
# File 'lib/croupier.rb', line 41

def error_message(msg)
  STDERR.puts msg
  STDERR.flush
end

.message(msg) ⇒ Object

Writes message to the standard output



35
36
37
38
# File 'lib/croupier.rb', line 35

def message(msg)
  STDOUT.puts msg
  STDOUT.flush
end

.stop(msg = "Error: Croupier finished.") ⇒ Object

Stops the execution of the Croupier application.



29
30
31
32
# File 'lib/croupier.rb', line 29

def stop(msg = "Error: Croupier finished.")
  self.error_message msg
  exit(false)
end

.trap_interruptObject

Trap SIGINT signal



58
59
60
61
62
# File 'lib/croupier.rb', line 58

def trap_interrupt
  trap('INT') do
    Croupier.stop("\nCroupier Exiting... Interrupt signal received.")
  end
end

.write(str) ⇒ Object

Writes to the standard output



47
48
49
50
# File 'lib/croupier.rb', line 47

def write(str)
  STDOUT.write str
  STDOUT.flush
end