nomener 0.2.9 → 0.2.10

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: 1a5d4f2bd5060c45197d9b93c147ecf4975b66a4
4
- data.tar.gz: 82d2f6e476c9fab3b3c18e1203fb7fc57cb7fe5d
3
+ metadata.gz: 8430696642a5042737102794198c6230189398ac
4
+ data.tar.gz: 997182835347c5b6aaee8ab4efdc115552708b5d
5
5
  SHA512:
6
- metadata.gz: a84f031b213de553071f89fbfc16d0efab68e2b69471e32c2c92aa35598c80f2e2a1520a0ecbd0b88c4262c605f77c879b57a085ee33578bfa548483b1ccee54
7
- data.tar.gz: 0783c6281f125eb7808772518e7bc3d0a26335625b3bb7d3340c59e4eb5f4c0ebcc1355864660d6550ffcbc66183133f2ccce0756e3c4322e27b9b829644b87e
6
+ metadata.gz: 76a55f700bc0664352a3d81c97ddc62d2fe52172c70b3bd30fd4a1b721e878dc8bd60bb4b3cff5bc36e2434781b5792a0333dc1490c89f8242c7947acb9f9041
7
+ data.tar.gz: b0efa1c9f181100140196ebefddb392afba225e5b5e498c6a61fab751c98168b7fe5d29be03672067eeb0157956511c277718eed89ba721173e12ca81775f4a3
data/.gitignore CHANGED
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
@@ -1,9 +1,13 @@
1
1
  #-- encoding: UTF-8
2
- require 'nomener/version'
2
+ require 'nomener/configuration'
3
3
  require 'nomener/name'
4
+ require 'nomener/version'
4
5
 
5
6
  # Base module for our names
6
7
  module Nomener
8
+ # hold the configuration object Nomener::Configuration
9
+ @@config = nil
10
+
7
11
  # Error class raised for the few times we aren't able to parse a name
8
12
  class ParseError < StandardError
9
13
  end
@@ -16,4 +20,30 @@ module Nomener
16
20
  def self.parse(name)
17
21
  Name.new(name).parse
18
22
  end
23
+
24
+ # Public: to configure the Nomener object
25
+ # can set individually or by block
26
+ # See Nomener::Configuration for more details on what may be set
27
+ #
28
+ # Returns the configuration object
29
+ def self.configure
30
+ @@config ||= Nomener::Configuration.new
31
+ yield config if block_given?
32
+ @@config
33
+ end
34
+
35
+ # Public: set the configuration to the Nomener::Configuration defaults
36
+ #
37
+ # Returns the configuration object
38
+ def self.reset
39
+ @@config = Nomener::Configuration.new
40
+ end
41
+
42
+ # Internal: Read accessor for configuration
43
+ #
44
+ # Returns the configuration
45
+ def self.config
46
+ self.configure unless @@config
47
+ @@config
48
+ end
19
49
  end
@@ -26,22 +26,20 @@ module Nomener
26
26
  # Needs to be fixed up for matching and non-english quotes
27
27
  #
28
28
  # name - the string to clean
29
- # double - the double quotes to replace others with "" by default
30
- # single - the single quotes to replace others with '' by default
31
29
  #
32
30
  # Returns a string which is (ideally) pretty much the same as it was given.
33
- def self.reformat(name, double = '""', single = "''")
31
+ def self.reformat(name)
34
32
  @@allowable = %r![^\p{Alpha}\-&\/\ \.\,\'\"\(\)
35
- #{double[0] || '"'}
36
- #{double[1] || '"'}
37
- #{single[0] || "'"}
38
- #{single[1] || "'"}] !x unless @@allowable
33
+ #{Nomener.config.left}
34
+ #{Nomener.config.right}
35
+ #{Nomener.config.single}
36
+ ] !x unless @@allowable
39
37
 
40
38
  # remove illegal characters, translate fullwidth down
41
39
  nomen = name.dup.scrub.tr("\uFF02\uFF07", "\u0022\u0027")
42
40
 
43
- nomen = replace_doubles(nomen, double)
44
- replace_singles(nomen, single)
41
+ nomen = replace_doubles(nomen)
42
+ replace_singles(nomen)
45
43
  .gsub(/@@allowable/, ' ')
46
44
  .squeeze(' ')
47
45
  .strip
@@ -69,11 +67,10 @@ module Nomener
69
67
  # Internal: Replace various double quote characters with given char
70
68
  #
71
69
  # str - the string to find replacements in
72
- # double - string with two characters, the left and right quotes
73
70
  #
74
71
  # Returns the string with the quotes replaced
75
- def self.replace_doubles(str, double)
76
- left, right = quotes_from double
72
+ def self.replace_doubles(str)
73
+ left, right = [Nomener.config.left, Nomener.config.right]
77
74
 
78
75
  # replace left and right double quotes
79
76
  str.tr("\u0022\u00AB\u201C\u201E\u2036\u300E\u301D\u301F\uFE43", left)
@@ -84,19 +81,18 @@ module Nomener
84
81
  # Internal: Replace various single quote characters with given chars
85
82
  #
86
83
  # str - the string to find replacements in
87
- # double - string with two characters, the left and right quotes
88
84
  #
89
85
  # Returns the string with the quotes replaced
90
- def self.replace_singles(str, single)
91
- left, right = quotes_from single
86
+ def self.replace_singles(str)
92
87
 
93
88
  # replace left and right single quotes
94
- str.tr("\u0027\u2018\u201A\u2035\u2039\u300C\uFE41\uFF62", left)
95
- .tr("\u0027\u2019\u201B\u2032\u203A\u300D\uFE42\uFF62", right)
89
+ str.tr("\u0027\u2018\u201A\u2035\u2039\u300C\uFE41\uFF62", Nomener.config.single)
90
+ .tr("\u0027\u2019\u201B\u2032\u203A\u300D\uFE42\uFF62", Nomener.config.single)
96
91
  end
97
92
  private_class_method :replace_singles
98
93
 
99
94
  # Internal: Get the quotes from a string
95
+ # Currently unused. To Be Removed.
100
96
  #
101
97
  # str - the string of two characters for the left and right quotes
102
98
  #
@@ -0,0 +1,39 @@
1
+ #-- encoding: UTF-8
2
+
3
+ # configuration module for our names
4
+ module Nomener
5
+ class Configuration
6
+ attr_accessor :lquote, :rquote, :squote, :language, :direction, :format
7
+
8
+ # initializes the configuration object
9
+ def initialize
10
+ @lquote = '"'
11
+ @rquote = '"'
12
+ @squote = '\''
13
+ @language = :en
14
+ @direction = :ltr
15
+ @format = '%f %m %l'
16
+ end
17
+
18
+ alias_method :left_quote=, :lquote=
19
+ alias_method :left_quote, :lquote
20
+ alias_method :left=, :lquote=
21
+ alias_method :left, :lquote
22
+
23
+ alias_method :right_quote=, :rquote=
24
+ alias_method :right_quote, :rquote
25
+ alias_method :right=, :rquote=
26
+ alias_method :right, :rquote
27
+
28
+ alias_method :single_quote=, :squote=
29
+ alias_method :single_quote, :squote
30
+ alias_method :single=, :squote=
31
+ alias_method :single, :squote
32
+
33
+ alias_method :lang=, :language=
34
+ alias_method :lang, :language
35
+
36
+ alias_method :dir=, :direction=
37
+ alias_method :dir, :direction
38
+ end
39
+ end
@@ -31,24 +31,25 @@ module Nomener
31
31
  #
32
32
  # Returns a string of the full name in a proper (western) case
33
33
  def properlike
34
- [capit(title), capit(first),
35
- (nick.to_s.empty? ? '' : "\"#{nick}\""),
36
- capit(middle), capit(last),
34
+ [capit(title),
35
+ capit(first),
36
+ (nick.to_s.empty? ? '' : "#{Nomener.config.left}#{nick}#{Nomener.config.right}"),
37
+ capit(middle),
38
+ capit(last),
37
39
  suffix
38
40
  ].join(' ').strip.squeeze ' '
39
41
  end
40
42
 
41
- # Internal: try to capitalize last names with Mac and Mc and D' and such
43
+ # Internal: try to capitalize names including tough ones like Mac and Mc and D' and such
42
44
  #
43
- # last - string of the name to capitalize
45
+ # nomen - string of the name to capitalize
44
46
  #
45
47
  # Returns a string of the capitalized name
46
- def capit(last)
47
- fix = last.to_s.dup
48
-
49
- # if there are multiple last names separated by a dash
50
- fix = fix.split('-')
51
- .map { |outer| outer.split(' ').map(&:capitalize).join ' ' }.join '-'
48
+ def capit(nomen)
49
+ # if there are multiple names separated by a dash
50
+ fix = nomen.to_s.dup.split('-').map do |outer|
51
+ outer.split(' ').map(&:capitalize).join ' '
52
+ end.join '-'
52
53
 
53
54
  # anything begining with Mac and not ending in [aciozj], except for a few
54
55
  fix.sub!(/Mac(?!
@@ -131,7 +132,7 @@ module Nomener
131
132
  #
132
133
  # Returns the full name
133
134
  def full
134
- name '%f %m %l'
135
+ name Nomener.config.format
135
136
  end
136
137
  alias_method :fullname, :full
137
138
 
@@ -1,5 +1,5 @@
1
1
  #-- encoding: UTF-8
2
2
  # Module defining the Nomener version
3
3
  module Nomener
4
- VERSION = '0.2.9'
4
+ VERSION = '0.2.10'
5
5
  end
File without changes
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  RSpec.describe "Nomener" do
5
5
  it "has the class method parse" do
6
- expect(Nomener.singleton_methods).to match_array [:parse]
6
+ expect(Nomener.singleton_methods).to include :parse
7
7
  end
8
8
 
9
9
  context "with the method parse" do
@@ -29,4 +29,70 @@ RSpec.describe "Nomener" do
29
29
  expect(parser.last).to eq "Smith"
30
30
  end
31
31
  end
32
+
33
+ context "with configure" do
34
+ after(:each) do
35
+ Nomener.reset
36
+ end
37
+
38
+ it "can be configured" do
39
+ config = Nomener.configure
40
+ expect(config).to be_a Nomener::Configuration
41
+ end
42
+
43
+ it "can be reset" do
44
+ config = Nomener.reset
45
+ expect(config.left).to eq '"'
46
+ expect(config.right).to eq '"'
47
+ expect(config.single).to eq '\''
48
+ expect(config.lang).to eq :en
49
+ end
50
+
51
+ it "can configure the left quote" do
52
+ Nomener.config.left = ':'
53
+ expect(Nomener.config.left).to eq ':'
54
+ end
55
+
56
+ it "can configure the right quote" do
57
+ Nomener.config.right = ':'
58
+ expect(Nomener.config.right).to eq ':'
59
+ end
60
+
61
+ it "can configure the single quote" do
62
+ Nomener.config.single = ':'
63
+ expect(Nomener.config.single).to eq ':'
64
+ end
65
+
66
+ it "can configure the language" do
67
+ Nomener.config.lang = :fr
68
+ expect(Nomener.config.lang).to eq :fr
69
+ end
70
+
71
+ it "can configure the direction" do
72
+ Nomener.config.dir = :rtl
73
+ expect(Nomener.config.dir).to eq :rtl
74
+ end
75
+
76
+ it "can configure the name format" do
77
+ Nomener.config.format = '%f %l'
78
+ expect(Nomener.config.format).to eq '%f %l'
79
+ end
80
+
81
+ it "can be configured with a block" do
82
+ Nomener.configure do |con|
83
+ con.left = '-'
84
+ con.right = '*'
85
+ con.single = '^'
86
+ con.format = '%f'
87
+ con.dir = :rtl
88
+ con.lang = :de
89
+ end
90
+ expect(Nomener.config.left).to eq '-'
91
+ expect(Nomener.config.right).to eq '*'
92
+ expect(Nomener.config.single).to eq '^'
93
+ expect(Nomener.config.format).to eq '%f'
94
+ expect(Nomener.config.dir).to eq :rtl
95
+ expect(Nomener.config.lang).to eq :de
96
+ end
97
+ end
32
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dante Piombino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,7 @@ files:
84
84
  - lib/nomener/base.rb
85
85
  - lib/nomener/cleaner.rb
86
86
  - lib/nomener/compounders.rb
87
+ - lib/nomener/configuration.rb
87
88
  - lib/nomener/name.rb
88
89
  - lib/nomener/parser.rb
89
90
  - lib/nomener/suffixes.rb