Module: Quickl::Naming

Included in:
Command, Command::Robustness
Defined in:
lib/quickl/naming.rb

Instance Method Summary collapse

Instance Method Details

#command2module(name) ⇒ Object

Converts a command name to a module name. Implements the following conversions:

hello -> Hello
hello-world -> HelloWorld

This method is part of Quickl’s private interface even if its effect are considered public.



14
15
16
17
18
19
20
21
22
23
# File 'lib/quickl/naming.rb', line 14

def command2module(name)
  case name
    when String
      name.gsub(/^(.)|-(.)/){|x| x.upcase}.gsub(/-/,'')
    when Symbol
      command2module(name.to_s).to_sym
    else
      raise ArgumentError, "Invalid name argument #{name.class}"
  end
end

#module2command(mod) ⇒ Object

Converts a module name to a command name. Implements the following conversions:

Hello -> hello
HelloWorld -> hello-world

This method is part of Quickl’s private interface even if its effect are considered public.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quickl/naming.rb', line 35

def module2command(mod)
  case mod
    when Module
      name = RubyTools::class_unqualified_name(mod)
      name = name.gsub(/[A-Z]/){|x| "-#{x.downcase}"}[1..-1]
    when String
      name = mod.to_s
      name = name.gsub(/[A-Z]/){|x| "-#{x.downcase}"}[1..-1]
    when Symbol
      name = mod.to_s
      name = name.gsub(/[A-Z]/){|x| "-#{x.downcase}"}[1..-1]
      name.to_sym
    else
      raise ArgumentError, "Invalid module argument #{mod.class}"
  end
end