nomener 0.2.4 → 0.2.6

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: 2b4d3e3d0da16de4111205c7c0355bd8db5526a5
4
- data.tar.gz: 314c165d421692570ebf48a64cbfdc9748f22c70
3
+ metadata.gz: 2c250686ec8119b88c20fe08ee5e4ecd720411b5
4
+ data.tar.gz: 1efeb93999ebf6d3ccc9b879c9ac0a0c84696cac
5
5
  SHA512:
6
- metadata.gz: 3d1d2126b1bb6a6e6e4622a5eae671157dae540515137e2862f224a399d8e6b19c9d6f21e74796f4be2c4f47f51cf4cb7280533ce0aef79eaf121571801a9309
7
- data.tar.gz: 3527b6b3e9fcbb1e3d8d317ad4d25ec1eee6ff926377722bf32581b13b47a1fff56a04cded4929955a0bc37365c88b250eced36a4a0c6558247506b0ef19f7f2
6
+ metadata.gz: 1e66b1549074d0ffd816aae1bc4c84cc143a324f09e94e23ddcd0c61b29d04fe497e275a508d7320dba446370e5a528ecd03ea105ab5baa978bf3c30876c300d
7
+ data.tar.gz: 3b2fbf3c124d97965e8836eed594276041a5135079f162ca2024f213ac08a894e7467f3fcf69101cdc9edadf4d4e124a73dc76c97a54d3f5f74433d028a3f384
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ install: bundle install --jobs=3 --retry=3
3
+ script: bundle exec rspec
4
+
5
+ sudo: false
6
+
7
+ rvm:
8
+ - 2.2.0
9
+ - 2.1.0
10
+ - 2.0.0
11
+ - 1.9.3
12
+ # - rbx-2
13
+ notifications:
14
+ email: false
15
+ matrix:
16
+ fast_finish: true
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # Nomener
2
2
  [![Gem Version](https://badge.fury.io/rb/nomener.svg)](http://badge.fury.io/rb/nomener)
3
+ [![Build Status](https://travis-ci.org/dan-ding/nomener.svg?branch=master)](https://travis-ci.org/dan-ding/nomener)
3
4
 
4
- Nomener assists with parsing peoples names that they give themselves (or other people). Nomener is a fork of [People](https://github.com/dan-ding/people) as it uses some code contributed there. It's currently geared towards western style name formatting, however other cultural name formatting is (or would like to be supported).Currently it attempts to parse names through pattern matching without using dictionary/library/data files (except for name decorations and suffixes, see usage). It may not be possible to do without such in all languages.
5
+ Nomener assists with parsing peoples names that they give themselves (or other people). Nomener ~~is~~ was a fork of [People](https://github.com/dan-ding/people) as it uses some code contributed there. It's currently geared towards western style name formatting, however other cultural name formatting is (or would like to be supported). Currently it attempts to parse names through pattern matching without using large(r) dictionary/library/data files (except for name decorations and suffixes, see usage). It may not be possible to do without such in all languages.
5
6
 
6
7
  If you didn't know, parsing names can be much more difficult than it seems it should be.
7
8
 
8
9
  ## Requirements
9
10
 
10
- Requires Ruby 2.1 or higher (or equivalent).
11
- To use with 1.9 or 2.0 you'll need to install either [https://github.com/hsbt/string-scrub](string-scrub) or [https://github.com/jrochkind/scrub_rb](scrub_rb).
11
+ Requires Ruby 1.9.3 or higher (or equivalent).
12
+ If using Ruby 1.9.3 or 2.0.0, it depends on [string-scrub](https://github.com/hsbt/string-scrub)
12
13
 
13
14
  ## Installation
14
15
 
@@ -33,11 +34,16 @@ name = Nomener.parse "Joe Smith" # <Nomener::Name first="Joe" last="Smith">
33
34
 
34
35
  Create a new instance:
35
36
  ```ruby
36
- name = Nomener::Name.new "Joe Smith" # <Nomener::Name >
37
- name.parse # <Nomener::Name first="Joe" last="Smith">
37
+ name = Nomener::Name.new "Duke Joe (Henry) Smith Jr."
38
+ # name is <Nomener::Name title="Duke" first="Joe" nick="Henry" last="Smith" suffix="Jr">
39
+
38
40
  name.first # Joe
39
41
  name.name # Joe Smith
40
42
  "Hi #{name}!" # Hi Joe Smith!
43
+ name.last # Smith
44
+ name.title # "Duke"
45
+ name.suffix # "Jr"
46
+ name.nick # "Henry"
41
47
  ```
42
48
 
43
49
  ## TODO
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require "bundler/gem_tasks"
2
3
 
3
4
  begin
@@ -27,4 +28,35 @@ end
27
28
  task :rspec do
28
29
  RSpec::Core::RakeTask.new(:spec)
29
30
  Rake::Task["spec"].execute
30
- end
31
+ end
32
+
33
+ # from https://github.com/chiliproject/chiliproject/blob/master/lib/tasks/code.rake
34
+ desc "Set the magic encoding comment everywhere to UTF-8"
35
+ task :source_encoding do
36
+ shebang = '\s*#!.*?(\n|\r\n)'
37
+ magic_regex = /\A(#{shebang})?\s*(#\W*(en)?coding:.*?$)/mi
38
+
39
+ magic_comment = '#-- encoding: UTF-8'
40
+
41
+ (Dir['script/**/**'] + Dir['**/**{.rb,.rake}']).each do |file_name|
42
+ next unless File.file?(file_name)
43
+
44
+ # We don't skip code here, as we need ALL code files to have UTF-8
45
+ # source encoding
46
+ file_content = File.read(file_name)
47
+ if file_content =~ magic_regex
48
+ file_content.gsub!(magic_regex, "\\1#{magic_comment}")
49
+ else
50
+ if file_content.start_with?("#!")
51
+ # We have a shebang. Encoding comment is to put on the second line
52
+ file_content.sub!(/(\n|\r\n)/, "\\1#{magic_comment}\\1")
53
+ else
54
+ file_content = magic_comment + "\n" + file_content
55
+ end
56
+ end
57
+
58
+ File.open(file_name, "w") do |file|
59
+ file.write file_content
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require "nomener/version"
2
3
  require "nomener/name"
3
4
  require "nomener/parser"
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  module Nomener
2
3
  module Compounders
3
4
  # Many of these are from http://en.wikipedia.org/wiki/List_of_family_name_affixes
@@ -1,3 +1,11 @@
1
+ #-- encoding: UTF-8
2
+
3
+ # For Ruby 1.9.3, 2.0.0
4
+ rv = RUBY_VERSION.split(".")[(0..1)].join("")
5
+ if rv >= '19' && rv < '21'
6
+ require "string-scrub"
7
+ end
8
+
1
9
  module Nomener
2
10
  module Helper
3
11
 
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require "nomener/parser"
2
3
 
3
4
  module Nomener
@@ -8,10 +9,15 @@ module Nomener
8
9
 
9
10
  # Public: Create an instance!
10
11
  def initialize(nomen = '')
11
- @original = Nomener::Helper.reformat(nomen.kind_of?(String) ? nomen : "")
12
+ @original = ""
13
+ if nomen.kind_of?(String)
14
+ @original = Nomener::Helper.reformat nomen
15
+ parse
16
+ end
12
17
  end
13
18
 
14
19
  # Public: Break down a string into parts of a persons name
20
+ # As of 0.2.5 parse no longer needs to be called after initialization, it's done automatically.
15
21
  #
16
22
  # name - A string of name to parse
17
23
  #
@@ -86,6 +92,21 @@ module Nomener
86
92
  "#<Nomener::Name #{each_pair.map { |k,v| [k,v.inspect].join('=') if (!v.nil? && !v.empty?) }.compact.join(' ')}>"
87
93
  end
88
94
 
95
+ # Public: an alias for the last name
96
+ #
97
+ # Returns a string of the last name
98
+ def surname
99
+ last
100
+ end
101
+ alias :family :surname
102
+
103
+ # Public: Return the first name
104
+ #
105
+ # Returns a string of the first name
106
+ def given
107
+ first
108
+ end
109
+
89
110
  # Public: Make the name a string.
90
111
  #
91
112
  # format - a string using symboles specifying the format of the name to return
@@ -140,5 +161,12 @@ module Nomener
140
161
  each_pair { |k, v| self[k] = other[k] }
141
162
  end
142
163
 
164
+ # Public: return self as a hash. For ruby 1.9.3
165
+ #
166
+ # Returns a hash of the name parts
167
+ def to_h
168
+ Hash[self.each_pair.to_a]
169
+ end unless method_defined?(:to_h)
170
+
143
171
  end
144
172
  end
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require "nomener/name"
2
3
  require "nomener/titles"
3
4
  require "nomener/suffixes"
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  module Nomener
2
3
  module Suffixes
3
4
 
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  module Nomener
2
3
  module Titles
3
4
 
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  module Nomener
2
- VERSION = "0.2.4"
3
+ VERSION = "0.2.6"
3
4
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # encoding: UTF-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'nomener/version'
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Dante Piombino"]
10
10
  spec.email = ["not@amusing.ninja"]
11
11
  spec.summary = %q{A(nother)? human name parser in ruby.}
12
- spec.description = %q{A human name parser in ruby.}
12
+ spec.description = %q{A human name parser in ruby. It attempts to determine name pieces like title, first name, surname, etc. }
13
13
  spec.homepage = "https://github.com/dan-ding/nomener"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,7 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = '>= 2.1'
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ rv = RUBY_VERSION.split(".")[(0..1)].join("")
24
+ if rv >= '19' && rv < '21'
25
+ spec.add_runtime_dependency "string-scrub", ">= 0.0.5"
26
+ end
22
27
 
23
28
  spec.add_development_dependency "bundler", "~> 1.5"
24
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Complex name parsing" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  # from http://www.theguardian.com/books/list/authorsaz
@@ -589,8 +590,13 @@ RSpec.describe "The Guardian author list" do
589
590
  expect(v).to eq(name[:to][k]), "got from #{k} - #{v} not #{name[:to][k]}"
590
591
  end
591
592
  end
593
+ name[:to].each_pair do |k,v|
594
+ unless (k == :full)
595
+ expect(v).to eq(parse_hash[k]), "got from #{k} - #{v} wanted #{parse_hash[k]} #{parse_hash}"
596
+ end
597
+ end
592
598
  end
593
599
  end
594
600
 
595
601
  end
596
- end
602
+ end
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
  # lots of names from wikiquote http://simple.wikiquote.org/wiki/List_of_people_by_name
3
4
  # minimal changes
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Name Parsing" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Compounders" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Helper" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Name" do
@@ -7,7 +8,7 @@ RSpec.describe "Nomener::Name" do
7
8
  name = Nomener::Name.new("Joe Smith")
8
9
  expect(name).to be_a Nomener::Name
9
10
  expect(name.original).to eq "Joe Smith"
10
- expect(name.values.delete_if {|i| i.nil? || i.empty? }).to eq []
11
+ expect(name.name).to eq "Joe Smith"
11
12
  end
12
13
 
13
14
  it "an empty Nomener::Name when given a non-string" do
@@ -35,7 +36,6 @@ RSpec.describe "Nomener::Name" do
35
36
  context "with parse" do
36
37
  it "it parses 'Joe Smith'" do
37
38
  name = Nomener::Name.new("Joe Smith")
38
- name.parse
39
39
  expect(name.first).to eq "Joe"
40
40
  expect(name.last).to eq "Smith"
41
41
  end
@@ -44,7 +44,6 @@ RSpec.describe "Nomener::Name" do
44
44
  context "with properlike" do
45
45
  it "returns the name in a nice case" do
46
46
  name = Nomener::Name.new("joE SmItH")
47
- name.parse
48
47
  expect(name.properlike).to eq "Joe Smith"
49
48
  end
50
49
  end
@@ -52,13 +51,11 @@ RSpec.describe "Nomener::Name" do
52
51
  context "with to_s" do
53
52
  it "returns the name in a original case" do
54
53
  name = Nomener::Name.new("joE SmItH")
55
- name.parse
56
54
  expect(name.to_s).to eq "joE SmItH"
57
55
  end
58
56
 
59
57
  it "can be used in a string" do
60
58
  name = Nomener::Name.new("Joe Smith")
61
- name.parse
62
59
  expect("Hello #{name}!").to eq "Hello Joe Smith!"
63
60
  end
64
61
  end
@@ -66,7 +63,6 @@ RSpec.describe "Nomener::Name" do
66
63
  context "with name" do
67
64
  it "follows the format and returns 'Bob Bob Bob' from 'Bob Smith'" do
68
65
  name = Nomener::Name.new("Bob Smith")
69
- name.parse
70
66
  expect(name.name("%f %f %f")).to eq "Bob Bob Bob"
71
67
  end
72
68
  end
@@ -74,7 +70,6 @@ RSpec.describe "Nomener::Name" do
74
70
  context "with full" do
75
71
  it "returns the entire parsed name as a string" do
76
72
  name = Nomener::Name.new("Mr. Joe Bob Smith")
77
- name.parse
78
73
  expect(name.full).to eq "Joe Bob Smith"
79
74
  end
80
75
  end
@@ -82,7 +77,6 @@ RSpec.describe "Nomener::Name" do
82
77
  context "with inspect" do
83
78
  it "details the object with only the parsed strings" do
84
79
  name = Nomener::Name.new("Mr. Joe Smith")
85
- name.parse
86
80
  expect(name.inspect).to eq '#<Nomener::Name title="Mr" first="Joe" last="Smith">'
87
81
  end
88
82
  end
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Parser" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Suffixes" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Nomener::Titles" do
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "Title" do
@@ -217,8 +218,8 @@ RSpec.describe "Title" do
217
218
  ].each do |name|
218
219
  it "parses #{name[:result]} from #{name[:name]}" do
219
220
  skip name[:skip] if name.has_key?(:skip)
220
- parsed = Nomener.parse(name[:name])
221
- expect(parsed.title).to eq name[:result]
221
+ parsed = Nomener::Parser.parse_title!(name[:name])
222
+ expect(parsed).to eq name[:result]
222
223
  end
223
224
  end
224
225
 
@@ -1,3 +1,4 @@
1
+ #-- encoding: UTF-8
1
2
  require 'simplecov'
2
3
  SimpleCov.start do
3
4
  add_filter "/spec/"
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.4
4
+ version: 0.2.6
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-11 00:00:00.000000000 Z
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
- description: A human name parser in ruby.
69
+ description: 'A human name parser in ruby. It attempts to determine name pieces like
70
+ title, first name, surname, etc. '
70
71
  email:
71
72
  - not@amusing.ninja
72
73
  executables: []
@@ -74,6 +75,7 @@ extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
76
77
  - ".gitignore"
78
+ - ".travis.yml"
77
79
  - Gemfile
78
80
  - LICENSE.txt
79
81
  - README.md
@@ -112,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  requirements:
113
115
  - - ">="
114
116
  - !ruby/object:Gem::Version
115
- version: '2.1'
117
+ version: 1.9.3
116
118
  required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  requirements:
118
120
  - - ">="