Module: Tools

Defined in:
lib/thm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.guidObject

Guid.new isn’t hard but this Module will expand



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

def guid
  guid = Guid.new # Generate GUID
end

.log_errors(file, data) ⇒ Object

Thm system errors



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

def log_errors(file, data)
  File.open("#{file}", 'a') {|n|
    n.puts("#{data}")
  }
end

.ua_parser(agent) ⇒ Object

User agent parsing magic for Trafviz via uap-ruby on Github



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

def ua_parser(agent)
  # Load all user agent data / regexp / patterns once
  @ua ||= UserAgentParser::Parser.new
  @ua.parse(agent)
end

Instance Method Details

#use_const_defined_unless?(const) ⇒ Boolean

User defined functions

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/thm.rb', line 56

def use_const_defined_unless?(const)
  const_down = const.downcase
  if Kernel.const_defined?("#{const}")
    if instance_variable_get("@#{const_down}") == nil
      instance_variable_set("@#{const_down}", Kernel.const_get("#{const}"))
      puts "Config Constant #{const}: #{Kernel.const_get("#{const}")}"
      puts "Instance Variable @#{const_down}: #{instance_variable_get("@#{const_down}")}"
    else
      puts "Param via Getoptlong: Instance Variable #{@const_down}: #{instance_variable_get("@#{const_down}")}"
    end
  else
    raise "No Config option set add #{const} to your config.rb"
  end
end