Sha256: f5dd0be74932d7b34499e3361b7e887f3d41f229c73b6e6e6d19456aa7261398

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

module Quickl
  module Naming
    
    #
    # 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.
    #
    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
    
    #
    # 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.
    #
    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
    
  end # module Naming
end # module Quickl

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
quickl-0.4.3 lib/quickl/naming.rb
quickl-0.4.2 lib/quickl/naming.rb
quickl-0.4.1 lib/quickl/naming.rb
quickl-0.4.0 lib/quickl/naming.rb
quickl-0.3.0 lib/quickl/naming.rb
quickl-0.2.2 lib/quickl/naming.rb