Class: Chemtrail::ClassNameInflector

Inherits:
Object
  • Object
show all
Defined in:
lib/chemtrail/class_name_inflector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name) ⇒ ClassNameInflector

Returns a new instance of ClassNameInflector.



4
5
6
# File 'lib/chemtrail/class_name_inflector.rb', line 4

def initialize(class_name)
  @class_name = class_name.to_s.dup
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



2
3
4
# File 'lib/chemtrail/class_name_inflector.rb', line 2

def class_name
  @class_name
end

Instance Method Details

#underscoreObject



8
9
10
11
12
13
# File 'lib/chemtrail/class_name_inflector.rb', line 8

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