Method: Ink::Model.classname

Defined in:
lib/webink/model.rb

.classname(str) ⇒ Object

Class method

This will check the parent module for existing classnames that match the input of the str parameter. Once found, it returns the class, not the string of the class.

param str:

some string

returns:

valid class or nil



478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/webink/model.rb', line 478

def self.classname(str)
  res = []
  if str[0] =~ /^[a-z]/
    str.scan(/((^|_)([a-z0-9]+))/) { |s|
      if s.length > 0
        res.push(s[2][0].upcase +
          ((s[2].length > 1) ? s[2][1,s[2].length] : ""))
      end
    }
  else
    res.push str
  end
  Module.const_get(res.join).is_a?(Class) ? Module.const_get(res.join) : nil
end