Class: Gtin2atc::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/gtin2atc/util.rb

Constant Summary collapse

@@archive =
Dir.pwd
@@today =
Date.today
@@logging =
false

Class Method Summary collapse

Class Method Details

.debug_msg(msg) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/gtin2atc/util.rb', line 33

def Util.debug_msg(msg)
  return unless @@logging
  Util.init
  if @@logging or defined?(MiniTest) then $stdout.puts Time.now.to_s + ': ' + msg; $stdout.flush; return end
  @@checkLog.puts("#{Time.now}: #{msg}")
  @@checkLog.flush
end

.get_archiveObject



13
14
15
# File 'lib/gtin2atc/util.rb', line 13

def Util.get_archive
  @@archive
end

.get_latest_and_dated_name(keyword, extension) ⇒ Object



40
41
42
43
# File 'lib/gtin2atc/util.rb', line 40

def Util.get_latest_and_dated_name(keyword, extension)
  return File.expand_path(File.join(Util.get_archive, keyword + '-latest' + extension)),
      File.expand_path(File.join(Util.get_archive, Util.get_today.strftime("#{keyword}-%Y.%m.%d" + extension)))
end

.get_todayObject



7
8
9
# File 'lib/gtin2atc/util.rb', line 7

def Util.get_today
  @@today
end

.info(msg) ⇒ Object



19
20
21
22
23
24
# File 'lib/gtin2atc/util.rb', line 19

def Util.info(msg)
  puts msg
  return unless @@logging
  Util.init
  @@checkLog.puts("#{Time.now}: #{msg}")
end

.initObject



25
26
27
28
29
30
31
32
# File 'lib/gtin2atc/util.rb', line 25

def Util.init
  return unless @@logging
  if not defined?(@@checkLog) or not @@checkLog
    name = File.join(@@archive, 'log.log')
    FileUtils.makedirs(@@archive)
    @@checkLog = File.open(name, 'a+')
  end
end

.set_archive_dir(archiveDir) ⇒ Object



10
11
12
# File 'lib/gtin2atc/util.rb', line 10

def Util.set_archive_dir(archiveDir)
  @@archive = archiveDir
end

.set_logging(default) ⇒ Object



16
17
18
# File 'lib/gtin2atc/util.rb', line 16

def Util.set_logging(default)
  @@logging = default
end