module NobleNames

The main Module that has all necessary functions to process names.

Constants

STANDARD_UPACE_SUPPORT

Records whether String#upcase supports UTF-8 characters.

SUPPORTED_LANGUAGES
VERSION

Attributes

configuration[W]

Public Class Methods

business_particle?(word) click to toggle source

Checks weither a word is in the business particle list @param [String] word The word in question. @return [Boolean] result `true` if `word` is a business-particle

`false` otherwise
# File lib/noble_names.rb, line 55
def business_particle?(word)
  Data.business_particles.in_particle_list? word
end
capitalize(word) click to toggle source

Upcases the first small letters in each word, seperated by hyphons. The word is also not capitalized if it already contains a capitalized letter. This is to allow Business Names to have custom capitalization. But beware, words seperated by spaces stay small. @return [String] the capitalized word. @example

capitalize('hans-ebert')  #=> 'Hans-Ebert'
capitalize('john')        #=> 'John'
capitalize('john james')  #=> 'John james'
capitalize('eBase')       #=> 'eBase'
# File lib/noble_names.rb, line 41
def capitalize(word)
  if word =~ /[A-Z]|Ä|Ö|Ü/
    word
  else
    word.gsub first_small_letters do |letter|
      upcase(letter)
    end
  end
end
configuration() click to toggle source
# File lib/noble_names/config.rb, line 10
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source

Here you can configure how the module behaves. @example Only use german

NobleNames.configure do |config|
  config.languages = :german
end

@example Use multiple languages

NobleNames.configure do |config|
  config.languages = [:german, :spanish]
end
# File lib/noble_names/config.rb, line 24
def self.configure
  yield(configuration)
end
correct_business_particles(words) click to toggle source

Corrects only the business particle and leaves the other words alone. @param [Array] words An array of words to be checked. @return [Array] words An array of corrected words. @example A Business Name

correct_business_particles([
  'cool', 'and', 'hip', 'gmbh'
])                    #=> ['cool', 'and', 'hip', 'GmbH']
# File lib/noble_names.rb, line 67
def correct_business_particles(words)
  words.map! do |word|
    if business_particle?(word)
      word
        .replace(Data.business_particles.particles[word.downcase])
    else
      noble_capitalize(word)
    end
  end
end
initialize() click to toggle source

This is wrapped in a method so it isn't immediatly evaluated when its loaded

# File lib/noble_names/initializer.rb, line 8
def self.initialize
  String.class_eval do
    include NobleNames::CoreExt::String
  end
end
noble_capitalize(word) click to toggle source

Capitalizes a word if it needs to be capitalized. @param [String] word the word that needs to be capitalized. @return [String] word the word either capitalized or not.

# File lib/noble_names.rb, line 18
def noble_capitalize(word)
  prefix = Data.nobility_prefixes.prefix?(word)
  if Data.nobility_particles.in_particle_list?(word)
    word.downcase
  elsif prefix
    capitalize(prefix) + capitalize(word.gsub(prefix, ''))
  else
    capitalize(word)
  end
end

Private Class Methods

first_small_letters() click to toggle source

A Regex literal to find the first letter of a string as well as the first letter after a hyphon. @return [Regexp] first_small_letters the regexp in question

# File lib/noble_names.rb, line 100
def first_small_letters
  /((\A.|(?<=\-).))/
end
upcase(letter) click to toggle source

Upcases a letter even if it is a german mutated vowel. @return [String] letter the upcased letter. @example

upcase('t')         #=> 'T'
# File lib/noble_names.rb, line 84
def upcase(letter)
  return letter.upcase if STANDARD_UPACE_SUPPORT
  match = letter.match(/ä|ö|ü/)
  if match
    case match.to_s
    when 'ä' then 'Ä'
    when 'ö' then 'Ö'
    when 'ü' then 'Ü'
    end
  else letter.upcase
  end
end