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
- STANDARD_UPACE_SUPPORT =
Records whether String#upcase supports UTF-8 characters.
(RUBY_VERSION.to_f >= 2.4)
- SUPPORTED_LANGUAGES =
i[german english french spanish portuguese dutch].freeze
- VERSION =
'1.0.0'.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.
-
.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.
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
55 56 57 |
# File 'lib/noble_names.rb', line 55 def 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.
41 42 43 44 45 46 47 48 49 |
# 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 |
.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.
67 68 69 70 71 72 73 74 75 76 |
# 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 ⇒ 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.
18 19 20 21 22 23 24 25 26 27 |
# 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 |