Module: Tools
- Defined in:
- lib/thm.rb
Class Method Summary collapse
-
.guid ⇒ Object
Guid.new isn’t hard but this Module will expand.
-
.log_errors(file, data) ⇒ Object
Thm system errors.
-
.ua_parser(agent) ⇒ Object
User agent parsing magic for Trafviz via uap-ruby on Github.
Instance Method Summary collapse
-
#use_const_defined_unless?(const) ⇒ Boolean
User defined functions.
Class Method Details
.guid ⇒ Object
Guid.new isn’t hard but this Module will expand
155 156 157 |
# File 'lib/thm.rb', line 155 def guid guid = Guid.new # Generate GUID end |
.log_errors(file, data) ⇒ Object
Thm system errors
167 168 169 170 171 |
# File 'lib/thm.rb', line 167 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
160 161 162 163 164 |
# File 'lib/thm.rb', line 160 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
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/thm.rb', line 176 def use_const_defined_unless?(const) const_down = const.downcase if Kernel.const_defined?("#{const}") unless instance_variable_defined?("@#{const_down}") 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 |