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/core_ext/string.rb
Overview
:nodoc:
Defined Under Namespace
Modules: CoreExt, Data Classes: Configuration
Constant Summary collapse
- SUPPORTED_LANGUAGES =
[:german, :english, :french, :spanish, :portuguese].freeze
- VERSION =
'0.1.3'.freeze
Class Attribute Summary collapse
Class Method Summary collapse
-
.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.
-
.first_small_letters ⇒ Regexp
A Regex literal to find the first letter of a string as well as the first letter after a hyphon.
-
.in_particle_list?(word) ⇒ Boolean
Checks weither a word is in the nobility particle list.
-
.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.
-
.prefix?(word) ⇒ String
Checks weither a word has a prefix as defined in
data/prefixes.ymland returns it. -
.upcase(letter) ⇒ String
Upcases a letter even if it is a german mutated vowel.
Class Attribute Details
.configuration ⇒ Object
9 10 11 |
# File 'lib/noble_names/config.rb', line 9 def configuration @configuration ||= Configuration.new end |
Class Method Details
.capitalize(word) ⇒ String
Upcases the first small letters in each word, seperated by hyphons. But beware, words seperated by spaces stay small.
32 33 34 35 36 |
# File 'lib/noble_names.rb', line 32 def self.capitalize(word) word.gsub first_small_letters do |letter| upcase(letter) end end |
.configure {|configuration| ... } ⇒ Object
Here you can configure how the module behaves.
23 24 25 |
# File 'lib/noble_names/config.rb', line 23 def self.configure yield(configuration) 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.
57 58 59 |
# File 'lib/noble_names.rb', line 57 def self.first_small_letters /((\A.|(?<=\-).))/ end |
.in_particle_list?(word) ⇒ Boolean
Checks weither a word is in the nobility particle list.
65 66 67 |
# File 'lib/noble_names.rb', line 65 def self.in_particle_list?(word) Data.particles.include? word end |
.initialize ⇒ Object
This is wrapped in a method so it isn't immediatly evaluated when its loaded
7 8 9 10 11 |
# File 'lib/noble_names/initializer.rb', line 7 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.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/noble_names.rb', line 13 def self.noble_capitalize(word) prefix = prefix?(word) if in_particle_list?(word) word.downcase elsif prefix capitalize(prefix) + capitalize(word.gsub(prefix, '')) else capitalize(word) end end |
.prefix?(word) ⇒ String
Checks weither a word has a prefix as defined in
data/prefixes.yml and returns it.
76 77 78 79 80 81 |
# File 'lib/noble_names.rb', line 76 def self.prefix?(word) Data.prefixes.each do |pre| return pre if (word =~ Regexp.new(pre)) == 0 end nil end |
.upcase(letter) ⇒ String
Upcases a letter even if it is a german mutated vowel.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/noble_names.rb', line 42 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 |