noble_names 0.1.5 → 1.0.0
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 +5 -5
- data/.rubocop.yml +9 -1
- data/.travis.yml +3 -5
- data/CHANGELOG.md +18 -0
- data/README.md +5 -2
- data/Rakefile +1 -1
- data/lib/noble_names.rb +82 -74
- data/lib/noble_names/config.rb +2 -2
- data/lib/noble_names/core_ext/string.rb +1 -1
- data/lib/noble_names/data.rb +8 -2
- data/lib/noble_names/initializer.rb +1 -1
- data/lib/noble_names/match_index.rb +15 -10
- data/lib/noble_names/version.rb +2 -2
- metadata +18 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: aca9a5ec054a904befe7713c8b1bb2de83b2badde064e28ba274ef0d94b74992
|
|
4
|
+
data.tar.gz: 67720c835320318c01b2193755928f82bde606db4ab360daa2cd76625fef4e83
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37c81bd00fb1ec5955179e1b6cecc2e278049be0b3bdb607d4307b7172d7b8bd118da9318c0cb79ae428ff1df7da872644c48b0e51dfcf1d9d63f7556e611a98
|
|
7
|
+
data.tar.gz: 84ab027a7ceb38f420c17410e6f9136592bc7bdc38297b517f4de1d4f88b0e82686aa477d8feb7c45f20d1847e948ac019ad4c1c6fc0b73bea1fd058391d65c9
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Layout/AlignParameters:
|
|
2
2
|
# Alignment of parameters in multi-line method calls.
|
|
3
3
|
#
|
|
4
4
|
# The `with_first_parameter` style aligns the following lines along the same
|
|
@@ -16,3 +16,11 @@ Style/AlignParameters:
|
|
|
16
16
|
SupportedStyles:
|
|
17
17
|
- with_first_parameter
|
|
18
18
|
- with_fixed_indentation
|
|
19
|
+
|
|
20
|
+
Metrics/BlockLength:
|
|
21
|
+
# Ignore the block lengths in these files as they are based on long blocks.
|
|
22
|
+
Exclude:
|
|
23
|
+
- 'Rakefile'
|
|
24
|
+
- '*.gemspec'
|
|
25
|
+
- '**/*.rake'
|
|
26
|
+
- 'test/**/*.rb'
|
data/.travis.yml
CHANGED
|
@@ -2,14 +2,12 @@ language: ruby
|
|
|
2
2
|
rvm:
|
|
3
3
|
- jruby
|
|
4
4
|
- 2.2.4
|
|
5
|
-
- 2.
|
|
6
|
-
-
|
|
7
|
-
- 2.
|
|
8
|
-
before_install: gem install bundler flay flog rubocop
|
|
5
|
+
- 2.3.3
|
|
6
|
+
- 2.4.1
|
|
7
|
+
- 2.5.0
|
|
9
8
|
install:
|
|
10
9
|
- bundle install --retry=3
|
|
11
10
|
script:
|
|
12
|
-
- bundle exec rake source_encoding
|
|
13
11
|
- bundle exec rake test
|
|
14
12
|
- bundle exec rubocop
|
|
15
13
|
- bundle exec flay
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
// Please add your own contribution below inside the Master section, no need to
|
|
4
|
+
// set a version number, that happens during a deploy.
|
|
5
|
+
//
|
|
6
|
+
// These docs are aimed at users rather than danger developers, so please limit technical
|
|
7
|
+
// terminology in here.
|
|
8
|
+
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
## master
|
|
12
|
+
|
|
13
|
+
### 1.0.0
|
|
14
|
+
|
|
15
|
+
* Added link to rubydocs documentation.
|
|
16
|
+
* Added project to code-climate.
|
|
17
|
+
* Added support for native UTF-8 upcasing for ruby `>= 2.4`.
|
|
18
|
+
* Drop support for ruby 1.9.3 and updated development dependencies.
|
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# NobleNames
|
|
2
2
|
[](https://travis-ci.org/Haniyya/noble_names)
|
|
3
|
+
[](http://www.rubydoc.info/gems/noble_names)
|
|
5
|
+
[](https://codeclimate.com/github/Haniyya/noble_names/maintainability)
|
|
3
6
|
|
|
4
7
|
A small Gem to capitalize names with regard to nobility particles and prefixes.
|
|
5
8
|
|
|
@@ -80,10 +83,10 @@ This gem has no runtime-dependencies outside of the standard library and is
|
|
|
80
83
|
therefore compatible with the following ruby versions:
|
|
81
84
|
|
|
82
85
|
- jruby
|
|
86
|
+
- 2.5.0
|
|
87
|
+
- 2.4.3
|
|
83
88
|
- 2.3.0
|
|
84
89
|
- 2.2.4
|
|
85
|
-
- 2.2.1
|
|
86
|
-
- 1.9.3
|
|
87
90
|
|
|
88
91
|
Other verions might work to but are not tested in ci so far.
|
|
89
92
|
|
data/Rakefile
CHANGED
data/lib/noble_names.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
require 'noble_names/match_index'
|
|
3
3
|
require 'noble_names/version'
|
|
4
4
|
require 'noble_names/config'
|
|
@@ -8,90 +8,98 @@ require 'noble_names/data'
|
|
|
8
8
|
# The main Module that has all necessary functions to
|
|
9
9
|
# process names.
|
|
10
10
|
module NobleNames
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
# @return [String] word the word either capitalized or not.
|
|
14
|
-
def self.noble_capitalize(word)
|
|
15
|
-
prefix = Data.nobility_prefixes.prefix?(word)
|
|
16
|
-
if Data.nobility_particles.in_particle_list?(word)
|
|
17
|
-
word.downcase
|
|
18
|
-
elsif prefix
|
|
19
|
-
capitalize(prefix) + capitalize(word.gsub(prefix, ''))
|
|
20
|
-
else
|
|
21
|
-
capitalize(word)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
11
|
+
# Records whether String#upcase supports UTF-8 characters.
|
|
12
|
+
STANDARD_UPACE_SUPPORT = (RUBY_VERSION.to_f >= 2.4)
|
|
24
13
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def self.capitalize(word)
|
|
38
|
-
if word =~ /[A-Z]|Ä|Ö|Ü/
|
|
39
|
-
word
|
|
40
|
-
else
|
|
41
|
-
word.gsub first_small_letters do |letter|
|
|
42
|
-
upcase(letter)
|
|
14
|
+
class << self
|
|
15
|
+
# Capitalizes a word if it needs to be capitalized.
|
|
16
|
+
# @param [String] word the word that needs to be capitalized.
|
|
17
|
+
# @return [String] word the word either capitalized or not.
|
|
18
|
+
def noble_capitalize(word)
|
|
19
|
+
prefix = Data.nobility_prefixes.prefix?(word)
|
|
20
|
+
if Data.nobility_particles.in_particle_list?(word)
|
|
21
|
+
word.downcase
|
|
22
|
+
elsif prefix
|
|
23
|
+
capitalize(prefix) + capitalize(word.gsub(prefix, ''))
|
|
24
|
+
else
|
|
25
|
+
capitalize(word)
|
|
43
26
|
end
|
|
44
27
|
end
|
|
45
|
-
end
|
|
46
28
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
# Upcases the first small letters in each word,
|
|
30
|
+
# seperated by hyphons.
|
|
31
|
+
# The word is also not capitalized if it already contains
|
|
32
|
+
# a capitalized letter. This is to allow Business Names
|
|
33
|
+
# to have custom capitalization.
|
|
34
|
+
# But beware, words seperated by spaces stay small.
|
|
35
|
+
# @return [String] the capitalized word.
|
|
36
|
+
# @example
|
|
37
|
+
# capitalize('hans-ebert') #=> 'Hans-Ebert'
|
|
38
|
+
# capitalize('john') #=> 'John'
|
|
39
|
+
# capitalize('john james') #=> 'John james'
|
|
40
|
+
# capitalize('eBase') #=> 'eBase'
|
|
41
|
+
def capitalize(word)
|
|
42
|
+
if word =~ /[A-Z]|Ä|Ö|Ü/
|
|
43
|
+
word
|
|
44
|
+
else
|
|
45
|
+
word.gsub first_small_letters do |letter|
|
|
46
|
+
upcase(letter)
|
|
47
|
+
end
|
|
58
48
|
end
|
|
59
|
-
else letter.upcase
|
|
60
49
|
end
|
|
61
|
-
end
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
# Checks weither a word is in the business particle list
|
|
52
|
+
# @param [String] word The word in question.
|
|
53
|
+
# @return [Boolean] result `true` if `word` is a business-particle
|
|
54
|
+
# `false` otherwise
|
|
55
|
+
def business_particle?(word)
|
|
56
|
+
Data.business_particles.in_particle_list? word
|
|
57
|
+
end
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
# Corrects only the business particle and leaves the
|
|
60
|
+
# other words alone.
|
|
61
|
+
# @param [Array] words An array of words to be checked.
|
|
62
|
+
# @return [Array] words An array of corrected words.
|
|
63
|
+
# @example A Business Name
|
|
64
|
+
# correct_business_particles([
|
|
65
|
+
# 'cool', 'and', 'hip', 'gmbh'
|
|
66
|
+
# ]) #=> ['cool', 'and', 'hip', 'GmbH']
|
|
67
|
+
def correct_business_particles(words)
|
|
68
|
+
words.map! do |word|
|
|
69
|
+
if business_particle?(word)
|
|
70
|
+
word
|
|
71
|
+
.replace(Data.business_particles.particles[word.downcase])
|
|
72
|
+
else
|
|
73
|
+
noble_capitalize(word)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
# Upcases a letter even if it is a german mutated vowel.
|
|
81
|
+
# @return [String] letter the upcased letter.
|
|
82
|
+
# @example
|
|
83
|
+
# upcase('t') #=> 'T'
|
|
84
|
+
def upcase(letter)
|
|
85
|
+
return letter.upcase if STANDARD_UPACE_SUPPORT
|
|
86
|
+
match = letter.match(/ä|ö|ü/)
|
|
87
|
+
if match
|
|
88
|
+
case match.to_s
|
|
89
|
+
when 'ä' then 'Ä'
|
|
90
|
+
when 'ö' then 'Ö'
|
|
91
|
+
when 'ü' then 'Ü'
|
|
92
|
+
end
|
|
93
|
+
else letter.upcase
|
|
93
94
|
end
|
|
94
95
|
end
|
|
96
|
+
|
|
97
|
+
# A Regex literal to find the first letter of a string
|
|
98
|
+
# as well as the first letter after a hyphon.
|
|
99
|
+
# @return [Regexp] first_small_letters the regexp in question
|
|
100
|
+
def first_small_letters
|
|
101
|
+
/((\A.|(?<=\-).))/
|
|
102
|
+
end
|
|
95
103
|
end
|
|
96
104
|
|
|
97
105
|
# Applies the core extension
|
data/lib/noble_names/config.rb
CHANGED
data/lib/noble_names/data.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
module NobleNames
|
|
3
3
|
# The module responsible for maintaining and delivering
|
|
4
4
|
# the match data as defined in the `data` directory.
|
|
@@ -13,7 +13,13 @@ module NobleNames
|
|
|
13
13
|
# Otherwise it calls super.
|
|
14
14
|
def self.method_missing(method, *args, &block)
|
|
15
15
|
var = instance_variable_get("@#{method}")
|
|
16
|
-
var ? var : super
|
|
16
|
+
var ? var : super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Remember to define respond_to_missing.
|
|
20
|
+
def self.respond_to_missing?(method, *args, &block)
|
|
21
|
+
var = instance_variable_get("@#{method}")
|
|
22
|
+
var ? true : super
|
|
17
23
|
end
|
|
18
24
|
end
|
|
19
25
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
require 'yaml'
|
|
3
3
|
|
|
4
4
|
module NobleNames
|
|
@@ -51,7 +51,7 @@ module NobleNames
|
|
|
51
51
|
# @return [Boolean] `true` if `word` is in the particle_list,
|
|
52
52
|
# `false` otherwise.
|
|
53
53
|
def in_particle_list?(word)
|
|
54
|
-
reindex if
|
|
54
|
+
reindex if languages != NobleNames.configuration.languages
|
|
55
55
|
particles.key? word
|
|
56
56
|
end
|
|
57
57
|
|
|
@@ -61,8 +61,8 @@ module NobleNames
|
|
|
61
61
|
# used languages.
|
|
62
62
|
def selected_data
|
|
63
63
|
@selected_data ||=
|
|
64
|
-
|
|
65
|
-
.select { |l|
|
|
64
|
+
data
|
|
65
|
+
.select { |l| languages.include? l.to_sym }
|
|
66
66
|
.values
|
|
67
67
|
.flatten
|
|
68
68
|
end
|
|
@@ -75,9 +75,9 @@ module NobleNames
|
|
|
75
75
|
# @example
|
|
76
76
|
# prefix?('mcdormer') #=> 'mc'
|
|
77
77
|
def prefix?(word)
|
|
78
|
-
reindex if
|
|
78
|
+
reindex if languages != NobleNames.configuration.languages
|
|
79
79
|
prefixes.each do |pre|
|
|
80
|
-
return pre
|
|
80
|
+
return pre unless (word =~ Regexp.new('^' + pre.to_s)).nil?
|
|
81
81
|
end
|
|
82
82
|
nil
|
|
83
83
|
end
|
|
@@ -86,10 +86,15 @@ module NobleNames
|
|
|
86
86
|
|
|
87
87
|
# Resets the state of the MatchIndex
|
|
88
88
|
def reindex
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
self.languages = NobleNames.configuration.languages
|
|
90
|
+
self.selected_data = nil
|
|
91
|
+
self.prefixes = nil
|
|
92
|
+
self.particles = nil
|
|
93
93
|
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
attr_accessor :languages
|
|
98
|
+
attr_writer :particles, :prefixes, :selected_data
|
|
94
99
|
end
|
|
95
100
|
end
|
data/lib/noble_names/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Martensen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,70 +16,70 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1
|
|
19
|
+
version: '1'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1
|
|
26
|
+
version: '1'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: flay
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '2'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '2'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: minitest
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 5
|
|
47
|
+
version: '5'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 5
|
|
54
|
+
version: '5'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: rake
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: '12'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
68
|
+
version: '12'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rubocop
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.
|
|
75
|
+
version: '0.52'
|
|
76
76
|
type: :development
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.
|
|
82
|
+
version: '0.52'
|
|
83
83
|
description: |2
|
|
84
84
|
This Gem uses a list of nobility particles to keep track of what to
|
|
85
85
|
capitalize and what not.
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- ".rubocop.yml"
|
|
94
94
|
- ".travis.yml"
|
|
95
95
|
- ".yardopts"
|
|
96
|
+
- CHANGELOG.md
|
|
96
97
|
- Gemfile
|
|
97
98
|
- LICENSE.txt
|
|
98
99
|
- README.md
|
|
@@ -131,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
132
|
version: '0'
|
|
132
133
|
requirements: []
|
|
133
134
|
rubyforge_project:
|
|
134
|
-
rubygems_version: 2.
|
|
135
|
+
rubygems_version: 2.7.3
|
|
135
136
|
signing_key:
|
|
136
137
|
specification_version: 4
|
|
137
138
|
summary: A gem that titleizes strings while respecting certain linguistic differences.
|
|
138
139
|
test_files: []
|
|
139
|
-
has_rdoc:
|