Class: MiGA::MiGA

Inherits:
Object
  • Object
show all
Includes:
MiGA
Defined in:
lib/miga/common.rb,
lib/miga/version.rb

Overview

Generic class used to handle system-wide information and methods, and parent of all other MiGA::* classes.

Constant Summary collapse

@@DEBUG =

Should debugging information be reported?

false
@@DEBUG_TRACE =

Should the trace of debugging information be reported?

false

Constants included from MiGA

CITATION, VERSION, VERSION_DATE, VERSION_NAME

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.CITATIONObject

Reference of MiGA.


55
# File 'lib/miga/version.rb', line 55

def self.CITATION ; CITATION ; end

.DEBUG(*args) ⇒ Object

Send debug message.


49
50
51
52
53
# File 'lib/miga/common.rb', line 49

def self.DEBUG *args
  $stderr.puts(*args) if @@DEBUG
  $stderr.puts caller.map{|v| v.gsub(/^/,"    ")}.join("\n") if
    @@DEBUG_TRACE
end

.DEBUG_OFFObject

Turn off debugging.


32
# File 'lib/miga/common.rb', line 32

def self.DEBUG_OFF() @@DEBUG=false end

.DEBUG_ONObject

Turn on debugging.


28
# File 'lib/miga/common.rb', line 28

def self.DEBUG_ON() @@DEBUG=true end

.DEBUG_TRACE_OFFObject

Turn off debug tracing (but not debugging).


43
44
45
# File 'lib/miga/common.rb', line 43

def self.DEBUG_TRACE_OFF
  @@DEBUG_TRACE=false
end

.DEBUG_TRACE_ONObject

Turn on debug tracing (and debugging).


36
37
38
39
# File 'lib/miga/common.rb', line 36

def self.DEBUG_TRACE_ON
  @@DEBUG_TRACE=true
  self.DEBUG_ON
end

.FULL_VERSIONObject

Complete version as string.


40
# File 'lib/miga/version.rb', line 40

def self.FULL_VERSION ; VERSION.join(".") ; end

.initialized?Boolean

Has MiGA been initialized?


57
58
59
60
# File 'lib/miga/common.rb', line 57

def self.initialized?
  File.exist?(File.expand_path(".miga_rc", ENV["MIGA_HOME"])) and
    File.exist?(File.expand_path(".miga_daemon.json", ENV["MIGA_HOME"]))
end

.LONG_VERSIONObject

Complete version with nickname and date as string.


44
45
46
47
# File 'lib/miga/version.rb', line 44

def self.LONG_VERSION
  "MiGA " + VERSION.join(".") + " - " + VERSION_NAME + " - " +
    VERSION_DATE.to_s
end

.root_pathObject

Root path to MiGA (as estimated from the location of the current file).


16
# File 'lib/miga/common.rb', line 16

def self.root_path ; File.expand_path("../../..", __FILE__) ; end

.tabulate(header, values) ⇒ Object

Tabulates an values, and Array of Arrays, all with the same number of entries as header. Returns an Array of String, one per line.


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/miga/common.rb', line 65

def self.tabulate(header, values)
  fields = [header.map{ |h| h.to_s }]
  fields << fields.first.map{ |h| h.gsub(/\S/, "-") }
  fields += values.map{ |row| row.map{ |cell| cell.nil? ? "?" : cell.to_s } }
  clen = fields.map{ |row|
    row.map{ |cell| cell.length } }.transpose.map{ |col| col.max }
  fields.map do |row|
    (0 .. clen.size-1).map do |col_n|
      col_n==0 ? row[col_n].rjust(clen[col_n]) : row[col_n].ljust(clen[col_n])
    end.join("  ")
  end
end

.VERSIONObject

Major.minor version as Float.


36
# File 'lib/miga/version.rb', line 36

def self.VERSION ; VERSION[0] ; end

.VERSION_DATEObject

Date of the current gem release.


51
# File 'lib/miga/version.rb', line 51

def self.VERSION_DATE ; VERSION_DATE ; end

Instance Method Details

#result_files_exist?(base, ext) ⇒ Boolean

Check if the result files exist with base name (String) followed by the ext values (Array of String).


81
82
83
84
85
86
# File 'lib/miga/common.rb', line 81

def result_files_exist?(base, ext)
  ext = [ext] unless ext.kind_of? Array
  ext.all? do |f|
    File.exist?(base + f) or File.exist?(base + f + ".gz")
  end
end