Class: Characterize::ControllerMacros::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/characterize/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Converter

Returns a new instance of Converter.



54
55
56
# File 'lib/characterize/controller.rb', line 54

def initialize(string)
  @string = string.to_s
end

Instance Method Details

#to_constant_nameObject



67
68
69
70
# File 'lib/characterize/controller.rb', line 67

def to_constant_name
  @string.gsub(/(?:^|_)([a-z])/){ $1.upcase }.gsub('/','::')
  # TODO: get platform-specific path delimiter
end

#to_object_nameObject



58
59
60
# File 'lib/characterize/controller.rb', line 58

def to_object_name
  to_path.split('/').last
end

#to_pathObject



62
63
64
65
# File 'lib/characterize/controller.rb', line 62

def to_path
  # TODO: get platform-specific path delimiter
  @string.gsub('::','/').gsub(/([A-Z])/){ "_#{$1.downcase}" }.gsub(/^_|\/_/,'/').sub(/^\//,'')
end