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, line 22
def self.const_for_name(name)
  name.split('::').inject(Object) {|b,n| b.const_get(n)}
end
data_dir() click to toggle source

Return the data directory for webgen.

# File lib/webgen/utils.rb, line 11
def self.data_dir
  unless defined?(@@data_dir)
    require 'rbconfig'
    @@data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'webgen'))
    @@data_dir = File.expand_path(File.join(RbConfig::CONFIG["datadir"], "webgen")) if !File.exist?(@@data_dir)
    raise "Could not find webgen data directory! This is a bug, report it please!" unless File.directory?(@@data_dir)
  end
  @@data_dir
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, line 27
def self.snake_case(str)
  str = str.dup
  str.gsub!(/::/, '/')
  str.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  str.gsub!(/([a-z])([A-Z])/,'\1_\2')
  str.downcase!
  str
end