Module: NobleNames
- Defined in:
- lib/noble_names.rb,
lib/noble_names/data.rb,
lib/noble_names/config.rb,
lib/noble_names/version.rb,
lib/noble_names/initializer.rb,
lib/noble_names/match_index.rb,
lib/noble_names/core_ext/string.rb
Overview
:nodoc:
Defined Under Namespace
Modules: CoreExt, Data Classes: Configuration, MatchIndex
Constant Summary collapse
- SUPPORTED_LANGUAGES =
[:german, :english, :french, :spanish, :portuguese, :dutch].freeze
- VERSION =
'0.1.5'.freeze
Class Attribute Summary collapse
Class Method Summary collapse
-
.business_particle?(word) ⇒ Boolean
Checks weither a word is in the business particle list.
-
.capitalize(word) ⇒ String
Upcases the first small letters in each word, seperated by hyphons.
-
.configure {|configuration| ... } ⇒ Object
Here you can configure how the module behaves.
-
.correct_business_particles(words) ⇒ Array
Corrects only the business particle and leaves the other words alone.
-
.first_small_letters ⇒ Regexp
A Regex literal to find the first letter of a string as well as the first letter after a hyphon.
-
.initialize ⇒ Object
This is wrapped in a method so it isn't immediatly evaluated when its loaded.
-
.noble_capitalize(word) ⇒ String
Capitalizes a word if it needs to be capitalized.
-
.upcase(letter) ⇒ String
Upcases a letter even if it is a german mutated vowel.
Class Attribute Details
.configuration ⇒ Object
10 11 12 |
# File 'lib/noble_names/config.rb', line 10 def configuration @configuration ||= Configuration.new end |
Class Method Details
.business_particle?(word) ⇒ Boolean
Checks weither a word is in the business particle list
74 75 76 |
# File 'lib/noble_names.rb', line 74 def self.business_particle?(word) Data.business_particles.in_particle_list? word end |
.capitalize(word) ⇒ String
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.
37 38 39 40 41 42 43 44 45 |
# File 'lib/noble_names.rb', line 37 def self.capitalize(word) if word =~ /[A-Z]|Ä|Ö|Ü/ word else word.gsub first_small_letters do |letter| upcase(letter) end end end |
.configure {|configuration| ... } ⇒ Object
Here you can configure how the module behaves.
24 25 26 |
# File 'lib/noble_names/config.rb', line 24 def self.configure yield(configuration) end |
.correct_business_particles(words) ⇒ Array
Corrects only the business particle and leaves the other words alone.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/noble_names.rb', line 86 def self.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 |
.first_small_letters ⇒ Regexp
A Regex literal to find the first letter of a string as well as the first letter after a hyphon.
66 67 68 |
# File 'lib/noble_names.rb', line 66 def self.first_small_letters /((\A.|(?<=\-).))/ end |
.initialize ⇒ Object
This is wrapped in a method so it isn't immediatly evaluated when its loaded
8 9 10 11 12 |
# File 'lib/noble_names/initializer.rb', line 8 def self.initialize String.class_eval do include NobleNames::CoreExt::String end end |
.noble_capitalize(word) ⇒ String
Capitalizes a word if it needs to be capitalized.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/noble_names.rb', line 14 def self.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 |
.upcase(letter) ⇒ String
Upcases a letter even if it is a german mutated vowel.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/noble_names.rb', line 51 def self.upcase(letter) match = letter.match(/ä|ö|ü/) if match case match.to_s when 'ä' then 'Ä' when 'ö' then 'Ö' when 'ü' then 'Ü' end else letter.upcase end end |