noble_names 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c5d9da46ce4f5d0cf223b6a634fc8dae69c1f5b
4
- data.tar.gz: b337349e71df3a4895c26b1ec006fe1a288e65b0
3
+ metadata.gz: 13ba2226740a52d259fe57676f0f6c1777ba3ab7
4
+ data.tar.gz: 9980b8da945a59d1ef21d001a7b0b28932749d75
5
5
  SHA512:
6
- metadata.gz: 2633569e625d6b881027d160115fc0691a595eee5db40adf1ee3e48787602f39276aea2e43b3647d4f402d8e50cdf1114e5a6088dc89aef9cfbe51f593241b11
7
- data.tar.gz: 2d44bd790a2f263cc7ddb7d7dfe70514eb2c585eb3df9a78e2ba139d9f62c404a438f7deb7dbb06e0b3753f7821df6d67c3a7d7a48ec2f7b9af9163725cf914e
6
+ metadata.gz: 25c51046e0c5dac382aa8ab952311e3e70c5b6769bce3fabb99a1ca28e19255b065a90789e937c5514d70ed6f57fa9e3c9f0c2fdd785cb68dcb7d23357024ed8
7
+ data.tar.gz: 372994cf60221fc9603da0e799aeac8c667685d6f1b6186c46a838793751ac4709b00a9b2b7c895cad72b841e6620a61d38f8d1065471c638d5acf4c8c3de5c5
data/lib/noble_names.rb CHANGED
@@ -1,24 +1,63 @@
1
+ # Coding: UTF-8
1
2
  require 'noble_names/version'
2
3
  require 'noble_names/config'
3
4
  require 'noble_names/initializer'
4
5
  require 'noble_names/data'
5
6
 
6
- # {include:file:README.md}
7
+ # The main Module that has all necessary functions to
8
+ # process names.
7
9
  module NobleNames
8
10
  # Capitalizes a word if it needs to be capitalized.
9
11
  # @param [String] word the word that needs to be capitalized.
10
- # @param [String] word the word either capitalized or not.
12
+ # @return [String] word the word either capitalized or not.
11
13
  def self.noble_capitalize(word)
12
14
  prefix = prefix?(word)
13
15
  if in_particle_list?(word)
14
- word
16
+ word.downcase
15
17
  elsif prefix
16
- prefix.capitalize + word.gsub(prefix, '').capitalize
18
+ capitalize(prefix) + capitalize(word.gsub(prefix, ''))
17
19
  else
18
- word.capitalize
20
+ capitalize(word)
19
21
  end
20
22
  end
21
23
 
24
+ # Upcases the first small letters in each word,
25
+ # seperated by hyphons.
26
+ # But beware, words seperated by spaces stay small.
27
+ # @return [String] the capitalized word.
28
+ # @example
29
+ # capitalize('hans-ebert') #=> 'Hans-Ebert'
30
+ # capitalize('john') #=> 'John'
31
+ # capitalize('john james') #=> 'John james'
32
+ def self.capitalize(word)
33
+ word.gsub first_small_letters do |letter|
34
+ upcase(letter)
35
+ end
36
+ end
37
+
38
+ # Upcases a letter even if it is a german mutated vowel.
39
+ # @return [String] letter the upcased letter.
40
+ # @example
41
+ # upcase('t') #=> 'T'
42
+ def self.upcase(letter)
43
+ match = letter.match(/ä|ö|ü/)
44
+ if match
45
+ case match.to_s
46
+ when 'ä' then 'Ä'
47
+ when 'ö' then 'Ö'
48
+ when 'ü' then 'Ü'
49
+ end
50
+ else letter.upcase
51
+ end
52
+ end
53
+
54
+ # A Regex literal to find the first letter of a string
55
+ # as well as the first letter after a hyphon.
56
+ # @return [Regexp] first_small_letters the regexp in question
57
+ def self.first_small_letters
58
+ /((\A.|(?<=\-).))/
59
+ end
60
+
22
61
  # Checks weither a word is in the nobility particle list.
23
62
  # @param [String] word the word that is checked.
24
63
  # @return [Boolean] `true` if `word` is in the particle_list,
@@ -1,3 +1,3 @@
1
1
  module NobleNames
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noble_names
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Martensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-22 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler