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.1.0'
Class Attribute Summary collapse
Class Method Summary collapse
-
.business_particle?(word) ⇒ Boolean
Checks whether 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
11 12 13 |
# File 'lib/noble_names/config.rb', line 11 def configuration @configuration ||= Configuration.new end |
Class Method Details
.business_particle?(word) ⇒ Boolean
Checks whether a word is in the business particle list
56 57 58 |
# File 'lib/noble_names.rb', line 56 def business_particle?(word) Data.business_particles.in_particle_list? word.downcase 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.
42 43 44 45 46 47 48 49 50 |
# File 'lib/noble_names.rb', line 42 def capitalize(word) if word.match?(/[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.
25 26 27 |
# File 'lib/noble_names/config.rb', line 25 def self.configure yield(configuration) end |
.correct_business_particles(words) ⇒ Array
Corrects only the business particle and leaves the other words alone.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/noble_names.rb', line 68 def correct_business_particles(words) words.map! do |word| if business_particle?(word) word .replace(Data.business_particles.particles[word.downcase]) else word end end end |
.initialize ⇒ Object
This is wrapped in a method so it isn't immediatly evaluated when its loaded
9 10 11 12 13 |
# File 'lib/noble_names/initializer.rb', line 9 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.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/noble_names.rb', line 19 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 |