noble_names 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +11 -1
- data/.yardopts +3 -0
- data/README.md +27 -10
- data/bin/build.sh +6 -0
- data/data/prefixes.yml +3 -0
- data/lib/noble_names.rb +33 -15
- data/lib/noble_names/config.rb +20 -0
- data/lib/noble_names/core_ext/string.rb +10 -0
- data/lib/noble_names/data.rb +28 -0
- data/lib/noble_names/initializer.rb +1 -0
- data/lib/noble_names/version.rb +1 -1
- metadata +38 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5d9da46ce4f5d0cf223b6a634fc8dae69c1f5b
|
4
|
+
data.tar.gz: b337349e71df3a4895c26b1ec006fe1a288e65b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2633569e625d6b881027d160115fc0691a595eee5db40adf1ee3e48787602f39276aea2e43b3647d4f402d8e50cdf1114e5a6088dc89aef9cfbe51f593241b11
|
7
|
+
data.tar.gz: 2d44bd790a2f263cc7ddb7d7dfe70514eb2c585eb3df9a78e2ba139d9f62c404a438f7deb7dbb06e0b3753f7821df6d67c3a7d7a48ec2f7b9af9163725cf914e
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Style/AlignParameters:
|
2
|
+
# Alignment of parameters in multi-line method calls.
|
3
|
+
#
|
4
|
+
# The `with_first_parameter` style aligns the following lines along the same
|
5
|
+
# column as the first parameter.
|
6
|
+
#
|
7
|
+
# method_call(a,
|
8
|
+
# b)
|
9
|
+
#
|
10
|
+
# The `with_fixed_indentation` style aligns the following lines with one
|
11
|
+
# level of indentation relative to the start of the line with the method call.
|
12
|
+
#
|
13
|
+
# method_call(a,
|
14
|
+
# b)
|
15
|
+
EnforcedStyle: with_fixed_indentation
|
16
|
+
SupportedStyles:
|
17
|
+
- with_first_parameter
|
18
|
+
- with_fixed_indentation
|
data/.travis.yml
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
+
- jruby
|
3
4
|
- 2.2.4
|
4
|
-
|
5
|
+
- 2.2.1
|
6
|
+
- 1.9.3
|
7
|
+
- 2.3.0
|
8
|
+
before_install: gem install bundler flay flog rubocop
|
9
|
+
install:
|
10
|
+
- bundle install --retry=3
|
11
|
+
script:
|
12
|
+
- bundle exec rake test
|
13
|
+
- bundle exec rubocop
|
14
|
+
- bundle exec flay
|
data/.yardopts
ADDED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# NobleNames
|
2
|
+
[![Build Status](https://travis-ci.org/Haniyya/noble_names.svg?branch=master)](https://travis-ci.org/Haniyya/noble_names)
|
2
3
|
|
3
|
-
A small Gem to capitalize names with regard to nobility particles.
|
4
|
+
A small Gem to capitalize names with regard to nobility particles and prefixes.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -26,18 +27,19 @@ require 'noble_names'
|
|
26
27
|
```
|
27
28
|
and use `String#to_title` to correctly format your names.
|
28
29
|
```ruby
|
29
|
-
"james of windsor".to_title
|
30
|
+
"james of windsor".to_title #=> "James of Windsor"
|
30
31
|
"joseph von und zu reinbeck".to_title #=> "Joseph von und zu Reinbeck"
|
32
|
+
"tywin mclannister".to_title #=> "Tywin McLannister"
|
31
33
|
```
|
32
34
|
you can also use the bang method:
|
33
35
|
```ruby
|
34
36
|
my_string = "joseph von und zu reinbeck"
|
35
37
|
my_string.to_title!
|
36
|
-
my_string
|
38
|
+
my_string #=> "Joseph von und zu Reinbeck"
|
37
39
|
```
|
38
40
|
|
39
41
|
### Languages
|
40
|
-
So far
|
42
|
+
So far English, German, French, Spanish and Portuguese are supported.
|
41
43
|
By default all available languages are used. If you want to configure which one
|
42
44
|
to use for your application, you can do it like so:
|
43
45
|
```ruby
|
@@ -54,14 +56,29 @@ This way other language particles will be ignored.
|
|
54
56
|
|
55
57
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
58
|
|
57
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
58
60
|
|
59
61
|
## Contributing
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
- Fork it ( https://github.com/Haniyya/noble_names/fork )
|
63
|
+
- Create your feature branch (git checkout -b my-new-feature)
|
64
|
+
- Commit your changes (git commit -am 'Add some feature')
|
65
|
+
- Push to the branch (git push origin my-new-feature)
|
66
|
+
- Create a new Pull Request
|
67
|
+
|
68
|
+
To add more particles or prefixes from other languages, just add them to the
|
69
|
+
`data/particles.yml` or `data/prefixes.yml` file respectively.
|
70
|
+
|
71
|
+
## Compatability
|
72
|
+
This gem has no runtime-dependencies outside of the standard library and is
|
73
|
+
therefore compatible with the following ruby versions:
|
74
|
+
|
75
|
+
- jruby
|
76
|
+
- 2.3.0
|
77
|
+
- 2.2.4
|
78
|
+
- 2.2.1
|
79
|
+
- 1.9.3
|
80
|
+
|
81
|
+
Other verions might work to but are not tested in ci so far.
|
65
82
|
|
66
83
|
## License
|
67
84
|
|
data/bin/build.sh
ADDED
data/data/prefixes.yml
ADDED
data/lib/noble_names.rb
CHANGED
@@ -1,28 +1,46 @@
|
|
1
1
|
require 'noble_names/version'
|
2
2
|
require 'noble_names/config'
|
3
3
|
require 'noble_names/initializer'
|
4
|
-
require '
|
4
|
+
require 'noble_names/data'
|
5
5
|
|
6
|
+
# {include:file:README.md}
|
6
7
|
module NobleNames
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
PARTICLES = YAML.load_file(File.expand_path(
|
12
|
-
'particles.yml', DATA_PATH
|
13
|
-
))['particles'].freeze
|
14
|
-
|
8
|
+
# Capitalizes a word if it needs to be capitalized.
|
9
|
+
# @param [String] word the word that needs to be capitalized.
|
10
|
+
# @param [String] word the word either capitalized or not.
|
15
11
|
def self.noble_capitalize(word)
|
16
|
-
|
12
|
+
prefix = prefix?(word)
|
13
|
+
if in_particle_list?(word)
|
14
|
+
word
|
15
|
+
elsif prefix
|
16
|
+
prefix.capitalize + word.gsub(prefix, '').capitalize
|
17
|
+
else
|
18
|
+
word.capitalize
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
22
|
+
# Checks weither a word is in the nobility particle list.
|
23
|
+
# @param [String] word the word that is checked.
|
24
|
+
# @return [Boolean] `true` if `word` is in the particle_list,
|
25
|
+
# `false` otherwise.
|
19
26
|
def self.in_particle_list?(word)
|
20
|
-
particles
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
Data.particles.include? word
|
28
|
+
end
|
29
|
+
|
30
|
+
# Checks weither a word has a prefix as defined in
|
31
|
+
# `data/prefixes.yml` and returns it.
|
32
|
+
# @param [String] word the word that needs to be checked.
|
33
|
+
# @return [String] pre the Prefix of the word. `nil` if
|
34
|
+
# it has none.
|
35
|
+
# @example
|
36
|
+
# prefix?('james mcdormer') #=> 'mc'
|
37
|
+
def self.prefix?(word)
|
38
|
+
Data.prefixes.each do |pre|
|
39
|
+
return pre if (word =~ Regexp.new(pre)) == 0
|
40
|
+
end
|
41
|
+
nil
|
24
42
|
end
|
25
43
|
|
26
|
-
#
|
44
|
+
# Applies the core extension
|
27
45
|
initialize
|
28
46
|
end
|
data/lib/noble_names/config.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
# :nodoc:
|
1
2
|
module NobleNames
|
3
|
+
SUPPORTED_LANGUAGES =
|
4
|
+
[:german, :english, :french, :spanish, :portuguese].freeze
|
5
|
+
|
2
6
|
class << self
|
3
7
|
attr_writer :configuration
|
4
8
|
|
@@ -7,19 +11,35 @@ module NobleNames
|
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
14
|
+
# Here you can configure how the module behaves.
|
15
|
+
# @example Only use german
|
16
|
+
# NobleNames.configure do |config|
|
17
|
+
# config.languages = :german
|
18
|
+
# end
|
19
|
+
# @example Use multiple languages
|
20
|
+
# NobleNames.configure do |config|
|
21
|
+
# config.languages = [:german, :spanish]
|
22
|
+
# end
|
10
23
|
def self.configure
|
11
24
|
yield(configuration)
|
12
25
|
end
|
13
26
|
|
27
|
+
# The Configuration-Class for NobleNames,
|
28
|
+
# Here you can set the languages you want supported.
|
14
29
|
class Configuration
|
15
30
|
def initialize
|
16
31
|
@languages = [:all]
|
17
32
|
end
|
18
33
|
|
34
|
+
# Setter for `@languages`.
|
35
|
+
# @param [Symbol] languages is turned into an `Array`.
|
19
36
|
def languages=(languages)
|
20
37
|
@languages = Array(languages)
|
21
38
|
end
|
22
39
|
|
40
|
+
# Returns all supported languages if `@languages` is set to
|
41
|
+
# `:all`. Returns the configured languages otherwise
|
42
|
+
# @return [Array] languages an array of language symbols.
|
23
43
|
def languages
|
24
44
|
@languages == [:all] ? SUPPORTED_LANGUAGES : @languages
|
25
45
|
end
|
@@ -1,14 +1,24 @@
|
|
1
1
|
module NobleNames
|
2
2
|
module CoreExt
|
3
|
+
# This Module gives {String} the capability to
|
4
|
+
# titleize itself.
|
3
5
|
module String
|
4
6
|
# Capitalizes each Word in a name
|
5
7
|
# except for those which are nobility particles
|
8
|
+
# @return [String] name a new String matching the old `self`
|
9
|
+
# titleized.
|
10
|
+
# @example Titleize names
|
6
11
|
# 'jamie jones'.to_title # => 'Jamie Jones'
|
7
12
|
# 'jamie of windsor'.to_title # => 'Jamie of Windsor'
|
8
13
|
def to_title
|
9
14
|
dup.to_title!
|
10
15
|
end
|
11
16
|
|
17
|
+
# Does the same as {String#to_title} but replaces the old string.
|
18
|
+
# @example Titleize a name
|
19
|
+
# str = 'jamie of windsor'
|
20
|
+
# str.to_title!
|
21
|
+
# str #=> 'Jamie of Windsor'
|
12
22
|
def to_title!
|
13
23
|
words = split(/\s+/)
|
14
24
|
words.map! { |w| NobleNames.noble_capitalize(w) }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module NobleNames
|
4
|
+
# The module responsible for maintaining and delivering
|
5
|
+
# the match data as defined in the `data` directory.
|
6
|
+
module Data
|
7
|
+
DATA_PATH = File.expand_path('../../../data/', __FILE__).freeze
|
8
|
+
MATCH_DATA = Hash[Dir.glob(DATA_PATH + '/*.yml').collect do |f|
|
9
|
+
yaml = YAML.load_file(f)
|
10
|
+
yaml.first
|
11
|
+
end]
|
12
|
+
|
13
|
+
def self.particles
|
14
|
+
select_languages(MATCH_DATA['particles'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.prefixes
|
18
|
+
select_languages(MATCH_DATA['prefixes'])
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.select_languages(collection)
|
22
|
+
collection
|
23
|
+
.select { |l| NobleNames.configuration.languages.include? l.to_sym }
|
24
|
+
.values
|
25
|
+
.flatten
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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.1.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2016-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,37 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 5.8.4
|
55
|
-
|
56
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: flay
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.8.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.37.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.37.2
|
83
|
+
description: |2
|
84
|
+
This Gem uses a list of nobility particles to keep track of what to
|
85
|
+
capitalize and what not.
|
57
86
|
email:
|
58
87
|
- paul.martensen@gmx.de
|
59
88
|
executables: []
|
@@ -61,17 +90,22 @@ extensions: []
|
|
61
90
|
extra_rdoc_files: []
|
62
91
|
files:
|
63
92
|
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
64
94
|
- ".travis.yml"
|
95
|
+
- ".yardopts"
|
65
96
|
- Gemfile
|
66
97
|
- LICENSE.txt
|
67
98
|
- README.md
|
68
99
|
- Rakefile
|
100
|
+
- bin/build.sh
|
69
101
|
- bin/console
|
70
102
|
- bin/setup
|
71
103
|
- data/particles.yml
|
104
|
+
- data/prefixes.yml
|
72
105
|
- lib/noble_names.rb
|
73
106
|
- lib/noble_names/config.rb
|
74
107
|
- lib/noble_names/core_ext/string.rb
|
108
|
+
- lib/noble_names/data.rb
|
75
109
|
- lib/noble_names/initializer.rb
|
76
110
|
- lib/noble_names/version.rb
|
77
111
|
homepage: https://github.com/Haniyya/noble_names
|