Class: Marsdawn::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/marsdawn/util.rb

Class Method Summary collapse

Class Method Details

.adapter(namespace, class_name, base_path) ⇒ Object



32
33
34
35
36
37
# File 'lib/marsdawn/util.rb', line 32

def self.adapter namespace, class_name, base_path
  unless namespace.const_defined?(class_name, false)
    require File.join(base_path, class_to_underscore(class_name))
  end
  namespace.const_get(class_name)
end

.attr_escape(str) ⇒ Object



28
29
30
# File 'lib/marsdawn/util.rb', line 28

def self.attr_escape str
  str.gsub(/"/, '\"')
end

.class_to_underscore(class_name) ⇒ Object



16
17
18
# File 'lib/marsdawn/util.rb', line 16

def self.class_to_underscore class_name
    class_name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr('-','_').downcase
end

.hash_symbolize_keys(hash, deep = false) ⇒ Object



5
6
7
8
9
10
# File 'lib/marsdawn/util.rb', line 5

def self.hash_symbolize_keys hash, deep=false
  hash.each_with_object({}) do |(key, val), ret|
    val = hash_symbolize_keys(val, deep) if deep && val.kind_of?(Hash)
    ret[key.to_sym] = val
  end
end

.hash_symbolize_keys_deep(hash) ⇒ Object



12
13
14
# File 'lib/marsdawn/util.rb', line 12

def self.hash_symbolize_keys_deep hash
  hash_symbolize_keys hash, true
end

.html_escape(str) ⇒ Object



24
25
26
# File 'lib/marsdawn/util.rb', line 24

def self.html_escape str
  CGI.escapeHTML str
end

.strip_tags(text) ⇒ Object



20
21
22
# File 'lib/marsdawn/util.rb', line 20

def self.strip_tags text
  text.gsub(/<[^>]*>/ui, '')
end