Module: Opstat::Common

Defined in:
lib/opstat-client/common.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.camelize(term) ⇒ Object



3
4
5
6
7
# File 'lib/opstat-client/common.rb', line 3

def self.camelize(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end

.constantize(class_name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/opstat-client/common.rb', line 9

def self.constantize(class_name)
  names = class_name.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |n|
    name = Opstat::Common.camelize(n)
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

Instance Method Details

#constantize(camel_cased_word) ⇒ Object



21
22
23
# File 'lib/opstat-client/common.rb', line 21

def constantize(camel_cased_word)
  Opstat::Common.constantize(camel_cased_word)
end