Class: Wlog::Helpers

Inherits:
Object
  • Object
show all
Includes:
StaticConfigurations
Defined in:
lib/wlog/domain/helpers.rb

Overview

Author:

  • Simon Symeonidis

Constant Summary

Constants included from StaticConfigurations

StaticConfigurations::AppDirectory, StaticConfigurations::AppName, StaticConfigurations::ConfigDirectory, StaticConfigurations::ConfigFile, StaticConfigurations::DataDirectory, StaticConfigurations::DefaultDb, StaticConfigurations::TaintFile, StaticConfigurations::TemplateDir

Class Method Summary collapse

Class Method Details

.break_string(string, numchars) ⇒ Object

Break the string to a different line

Parameters:

  • string

    is the string that we want processed.

  • numchars

    is the amount of characters max per line.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wlog/domain/helpers.rb', line 12

def self.break_string(string,numchars)
  return unless string
  desc , cl = "", 0
  string.split.each do |word|
    wlength = word.length
    if cl + wlength + 1 > numchars
      cl = 0
      desc.concat($/)
    end
    desc.concat(word).concat(" ")
    cl += wlength + 1
  end
  desc.chomp!
desc end

.database_exits?Boolean

Check to see if the database exists in the DataDirectory

Returns:

  • (Boolean)

    true if exists, otherwise false



29
30
31
# File 'lib/wlog/domain/helpers.rb', line 29

def self.database_exits?
  File.exists? "#{DataDirectory}#{ARGV[0] || DefaultDb}"
end

.first_setup?Boolean

Check if the application directory exists. If it does not, it’s a first time system run.

Returns:

  • (Boolean)


44
# File 'lib/wlog/domain/helpers.rb', line 44

def self.first_setup?; !File.exists? TaintFile end

.make_dirs!Object

Check to see if DataDirectory exists Create the data directory if it does not exist.



35
36
37
38
39
40
# File 'lib/wlog/domain/helpers.rb', line 35

def self.make_dirs!
  # Does the data dir path not exist?
  unless File.exists? DataDirectory
    FileUtils.mkdir_p DataDirectory
  end
nil end