Module: Webgen::Utils

Defined in:
lib/webgen/utils.rb,
lib/webgen/utils/tag_parser.rb,
lib/webgen/utils/external_command.rb

Overview

Namespace for classes and methods that provide common functionality.

Defined Under Namespace

Modules: ExternalCommand Classes: TagParser

Class Method Summary collapse

Class Method Details

.const_for_name(name) ⇒ Object

Return the object for the given absolute constant name.



23
24
25
# File 'lib/webgen/utils.rb', line 23

def self.const_for_name(name)
  name.split('::').inject(Object) {|b,n| b.const_get(n)}
end

.data_dirObject

Return the data directory for webgen.



12
13
14
15
16
17
18
19
20
# File 'lib/webgen/utils.rb', line 12

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) ⇒ Object

Transform the string in Module::CamelCase format into module/camel_case format.



28
29
30
31
32
33
34
35
# File 'lib/webgen/utils.rb', line 28

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