Module: Camping::CommandsHelpers

Defined in:
lib/camping/commands.rb

Defined Under Namespace

Classes: Route, RouteCollection, RoutesParser

Class Method Summary collapse

Class Method Details

.app_name_from_input(app_name) ⇒ Object

Helper method that generates an app name from command line input.



24
25
26
27
28
29
30
31
# File 'lib/camping/commands.rb', line 24

def self.app_name_from_input(app_name)
  app_name = :Camp if app_name == nil
  app_name = app_name.to_sym if app_name.class == String
  snake_app_name = to_snake_case(app_name)
  camel_app_name = to_camel_case(snake_app_name)

  {app_name: camel_app_name.to_sym, snake_name: snake_app_name, camel_name: camel_app_name}
end

.to_camel_case(string) ⇒ Object

transform app_name to camel Case



15
16
17
18
19
20
21
# File 'lib/camping/commands.rb', line 15

def self.to_camel_case(string)
  cammelled = ""
  to_snake_case(string).split("_").each do |seq|
    cammelled << seq.capitalize
  end
  cammelled
end

.to_snake_case(string) ⇒ Object

transform app_name to snake case



5
6
7
8
9
10
11
12
# File 'lib/camping/commands.rb', line 5

def self.to_snake_case(string)
  string = string.to_s if string.class == Symbol
  string.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end