Module: Quickl::Naming

Included in:
Command
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
# File 'lib/quickl/naming.rb', line 35

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