module Webgen::Utils
Namespace for classes and methods that provide common functionality.
Public Class Methods
const_for_name(name)
click to toggle source
Return the object for the given absolute constant name
.
# File lib/webgen/utils.rb 22 def self.const_for_name(name) 23 name.split('::').inject(Object) {|b,n| b.const_get(n)} 24 end
data_dir()
click to toggle source
Return the data directory for webgen.
# File lib/webgen/utils.rb 11 def self.data_dir 12 unless defined?(@@data_dir) 13 require 'rbconfig' 14 @@data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'webgen')) 15 @@data_dir = File.expand_path(File.join(RbConfig::CONFIG["datadir"], "webgen")) if !File.exist?(@@data_dir) 16 raise "Could not find webgen data directory! This is a bug, report it please!" unless File.directory?(@@data_dir) 17 end 18 @@data_dir 19 end
snake_case(str)
click to toggle source
Transform the string in Module::CamelCase format into module/camel_case format.
# File lib/webgen/utils.rb 27 def self.snake_case(str) 28 str = str.dup 29 str.gsub!(/::/, '/') 30 str.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') 31 str.gsub!(/([a-z])([A-Z])/,'\1_\2') 32 str.downcase! 33 str 34 end