Method: Icss::Meta::Type.klassname_for

Defined in:
lib/icss/type.rb

.klassname_for(obj) ⇒ Object

Converts a type name to its ruby (camel-cased) form. Works on class, name of class, or dotted (avro-style) namespace.name. Names will have an ‘Icss::’ prefix.

Examples:

Icss::Meta::Type.fullname_for('this.that.the_other')        # "Icss::This::That::TheOther"
Icss::Meta::Type.fullname_for(Icss::This::That::TheOther)   # "Icss::This::That::TheOther"
Icss::Meta::Type.fullname_for("Icss::This::That::TheOther") # "Icss::This::That::TheOther"


139
140
141
142
143
144
145
# File 'lib/icss/type.rb', line 139

def self.klassname_for(obj)
  return nil unless obj.present? && (obj.to_s =~ NORMAL_NAMED_CONSTANT_RE)
  nm = obj.to_s.gsub(/^:*Icss:+/, '').
    gsub(%r{::},'.').
    split('.').map(&:camelize).join('::')
  "::Icss::#{nm}"
end