Class: Device::Support

Inherits:
Object
  • Object
show all
Defined in:
lib/device/support.rb

Class Method Summary collapse

Class Method Details

.camelize(str) ⇒ Object



11
12
13
# File 'lib/device/support.rb', line 11

def self.camelize(str)
  str.split('_').map {|w| w.capitalize}.join
end

.class_to_path(klass) ⇒ Object



3
4
5
# File 'lib/device/support.rb', line 3

def self.class_to_path(klass)
  klass.to_s.downcase
end

.constantize(name) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/device/support.rb', line 19

def self.constantize(name)
  if ! name.empty? && Object.const_defined?(name)
    Object.const_get name
  else
    nil
  end
end

.path_to_class(path) ⇒ Object



7
8
9
# File 'lib/device/support.rb', line 7

def self.path_to_class(path)
  constantize(camelize(remove_extension(path)))
end

.remove_extension(path) ⇒ Object



15
16
17
# File 'lib/device/support.rb', line 15

def self.remove_extension(path)
  path.to_s.split(".")[-2].split("/").last
end