module Ore::Naming

Provides methods for guessing the namespaces and directories of projects. {Naming} uses the naming conventions of project names defined by the [Ruby Packaging Standard (RPS)](chneukirchen.github.com/rps/).

Public Instance Methods

module_of(word) click to toggle source

Guesses the module name for a word within a project name.

@param [String] word

The word within a project name.

@return [String]

The module name.

@since 0.1.1

# File lib/ore/naming.rb, line 79
def module_of(word)
  if @@common_namespaces.has_key?(word)
    @@common_namespaces[word]
  elsif @@namespace_acronyms.include?(word)
    word.upcase
  else
    word.capitalize
  end
end
modules_of(name) click to toggle source

Guesses the module names from a project name.

@param [String] name

The name of the project.

@return [Array<String>]

The module names for a project.
# File lib/ore/naming.rb, line 98
def modules_of(name)
  names_in(name).map do |words|
    words.split('_').map { |word| module_of(word) }.join
  end
end
names_in(name) click to toggle source

Splits the project name into individual names.

@param [String] name

The name to split.

@return [Array<String>]

The individual names of the project name.
# File lib/ore/naming.rb, line 62
def names_in(name)
  name.split('-').reject do |word|
    @@ignore_namespaces.include?(word)
  end
end
namespace_dirs_of(name) click to toggle source

Guesses the namespace directories within ‘lib/` for a project.

@param [String] name

The name of the project.

@return [Array<String>]

The namespace directories for the project.
# File lib/ore/naming.rb, line 141
def namespace_dirs_of(name)
  names_in(name).map { |word| underscore(word) }
end
namespace_of(name) click to toggle source

Guesses the full namespace for a project.

@param [String] name

The name of the project.

@return [String]

The full module namespace for a project.
# File lib/ore/naming.rb, line 113
def namespace_of(name)
  modules_of(name).join('::')
end
namespace_path_of(name) click to toggle source

Guesses the namespace directory within ‘lib/` for a project.

@param [String] name

The name of the project.

@return [String]

The namespace directory for the project.
# File lib/ore/naming.rb, line 154
def namespace_path_of(name)
  File.join(namespace_dirs_of(name))
end
underscore(name) click to toggle source

Converts a camel-case name to an underscored file name.

@param [String] name

The name to underscore.

@return [String]

The underscored version of the name.
# File lib/ore/naming.rb, line 126
def underscore(name)
  name.gsub(/[^A-Z_][A-Z][^A-Z_]/) { |cap|
    cap[0,1] + '_' + cap[1..-1]
  }.downcase
end