fake_british_toponym 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.hound.yml +3 -0
- data/.rubocop.yml +0 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +15 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +5 -0
- data/fake_british_toponym.gemspec +24 -0
- data/lib/fake_british_toponym/version.rb +3 -0
- data/lib/fake_british_toponym.rb +136 -0
- data/spec/fake_british_toponym_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- data/tasks/rspec.rake +3 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e92f720344f5905e03b9f365b6c29350deccb3b2
|
4
|
+
data.tar.gz: 8dd8b8ea66c5cfdd03929ee5a0e38f8282fa12a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26e1c31165aafc0245325a6592db9b4978f3d2be72eac7328a4ece15753e19836ab58294d99e62b7aa1ca368b7c31c7c8aa982be3fb2f3ae8c7df62929a774fb
|
7
|
+
data.tar.gz: 0d712562fd6488aa05900e2b0e97a75dd62693d74e8d3e765c32304e274cdb87ef249f057ffe54936688bb275e82d9ea16ade96361f230b2837e2983f789102a
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
File without changes
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
fake-british-toponyms
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "probability"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "codeclimate-test-reporter", require: false
|
7
|
+
gem "guard"
|
8
|
+
gem "guard-rspec", require: false
|
9
|
+
end
|
10
|
+
|
11
|
+
group :development, :test do
|
12
|
+
gem "pry"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alexander
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# FakeBritishToponym
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/alxndr/fake_british_toponym.svg?branch=master)](https://travis-ci.org/alxndr/fake_british_toponym)
|
4
|
+
[![Dependency Status](https://gemnasium.com/alxndr/fake_british_toponym.svg)](https://gemnasium.com/alxndr/fake_british_toponym)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/alxndr/fake_british_toponym/badges/gpa.svg)](https://codeclimate.com/github/alxndr/fake_british_toponym)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/alxndr/fake_british_toponym/badges/coverage.svg)](https://codeclimate.com/github/alxndr/fake_british_toponym)
|
7
|
+
|
8
|
+
Generate names of places that sound sorta British.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem "fake_british_toponym"
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install fake_british_toponym
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
$ pry
|
27
|
+
[0] main » require "fake_british_toponym"
|
28
|
+
=> true
|
29
|
+
[0] main » FakeBritishToponym.new
|
30
|
+
=> "Dunkirkton"
|
31
|
+
[0] main » FakeBritishToponym.new
|
32
|
+
=> "Midnocktondeen Crossing"
|
33
|
+
[0] main » FakeBritishToponym.new
|
34
|
+
=> "Port Aberglentun"
|
35
|
+
[0] main » FakeBritishToponym.new
|
36
|
+
=> "Lymetunmore Bight"
|
37
|
+
|
38
|
+
...that's all, folks!
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include? lib
|
4
|
+
require 'fake_british_toponym/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_british_toponym"
|
8
|
+
spec.version = FakeBritishToponym::VERSION
|
9
|
+
spec.authors = ["Alexander"]
|
10
|
+
spec.email = ["alxndr+gem@gmail.com"]
|
11
|
+
spec.description = "Generate place names that sound sorta British"
|
12
|
+
spec.summary = "A basic class which creates a string that sounds like it could be a town in the British Isles."
|
13
|
+
spec.homepage = "https://github.com/alxndr/fake_british_toponym"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require "probability"
|
2
|
+
|
3
|
+
class FakeBritishToponym < String
|
4
|
+
|
5
|
+
ANTEFIXES = %w( east great little new north old port saint south west )
|
6
|
+
PREFIXES = %w( aber avon ash bex birm blen brad bre burn car chef cul dal don dun ex gains glou hex hol in inver ips kil kings knock lan leigh lin lock lon long lough lyme man mannan mid middle mills moss new nor not oak ock old pad pen puds shrews stan stin sud sur swin tarn thorn tilly tre up wake wall well wey which wil win wor worth yar )
|
7
|
+
INFIXES = %w( beck caster ces cester cot er folk ford glen ham hamp her ill ing kirk more ness nock ter tun ton wich )
|
8
|
+
SUFFIXES = %w( bie borough bost born burgh bury bridge by carden cay chester church combe dale deen den don dun ey field firth fork forth frith garth gate head holm hop hurst inge keld lan land law leigh ley low minster moth mouth orth over pool rith rock sbury set shaw shep ship shire stead ster stone ter thorp tham thwait tyne well wich wold wick )
|
9
|
+
POSTFIXES = %w( bight castle crossing downs gate glen grove hall hamlet -in- marsh of -on- -on-the- river 's sands town -under- -upon- village water willow )
|
10
|
+
|
11
|
+
def initialize(**args)
|
12
|
+
args[:modifier] = true unless args.has_key? :modifier
|
13
|
+
args[:min_syllables] ||= 2
|
14
|
+
|
15
|
+
@pieces = []
|
16
|
+
|
17
|
+
add_prefix
|
18
|
+
|
19
|
+
args[:min_syllables].times do
|
20
|
+
add_infix
|
21
|
+
end
|
22
|
+
|
23
|
+
add_suffix if @pieces.length == 1 || 3.in(10)
|
24
|
+
|
25
|
+
add_decoration if args[:modifier] && 1.in(2)
|
26
|
+
|
27
|
+
@name = join_pieces
|
28
|
+
|
29
|
+
super @name # do some String-y things
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_str
|
33
|
+
@name.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def add_antefix
|
39
|
+
@pieces.unshift "#{random_antefix.capitalize} "
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_prefix
|
43
|
+
@pieces.push random_prefix.capitalize
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_infix
|
47
|
+
@pieces.push pick_infix
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_suffix
|
51
|
+
@pieces.push pick_suffix
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_postfix
|
55
|
+
pick = random_postfix
|
56
|
+
case pick
|
57
|
+
when /^-/ # "-on-the-", "-upon-", etc
|
58
|
+
@pieces.push pick
|
59
|
+
@pieces.push new_decoration_toponym
|
60
|
+
when "of"
|
61
|
+
@pieces.push " #{pick} "
|
62
|
+
@pieces.push new_decoration_toponym
|
63
|
+
when "'s"
|
64
|
+
@pieces.push "#{pick} "
|
65
|
+
@pieces.push new_decoration_toponym
|
66
|
+
else
|
67
|
+
@pieces.push " #{pick.capitalize}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_decoration
|
72
|
+
if 1.in(2)
|
73
|
+
add_antefix
|
74
|
+
else
|
75
|
+
add_postfix
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def pick_infix
|
80
|
+
begin
|
81
|
+
pick = random_infix
|
82
|
+
end while pick == @pieces.last # try not to double up syllables
|
83
|
+
double_last_letter_if_needed pick
|
84
|
+
pick
|
85
|
+
end
|
86
|
+
|
87
|
+
def pick_suffix
|
88
|
+
pick = random_suffix
|
89
|
+
double_last_letter_if_needed pick
|
90
|
+
pick
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_decoration_toponym
|
94
|
+
self.class.new modifier: false
|
95
|
+
end
|
96
|
+
|
97
|
+
%w(ante pre in suf post).each do |which|
|
98
|
+
define_method("random_#{which}fix") do
|
99
|
+
corpus = self.class.const_get("#{which.upcase}FIXES")
|
100
|
+
corpus.sample
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def double_last_letter_if_needed(pick)
|
105
|
+
double_last_letter if doubled_last_letter_needed?(pick)
|
106
|
+
end
|
107
|
+
|
108
|
+
def doubled_last_letter_needed?(pick)
|
109
|
+
return false unless begins_with_vowel? pick
|
110
|
+
return false if ends_with_vowel? @pieces.last
|
111
|
+
return false if ends_with_doubled_letters? @pieces.last
|
112
|
+
true
|
113
|
+
end
|
114
|
+
|
115
|
+
def begins_with_vowel?(word)
|
116
|
+
word.match(/^[aeiou]/)
|
117
|
+
end
|
118
|
+
|
119
|
+
def ends_with_vowel?(word)
|
120
|
+
word.match(/[aeiou]$/)
|
121
|
+
end
|
122
|
+
|
123
|
+
def ends_with_doubled_letters?(word)
|
124
|
+
word[-1] == word[-2]
|
125
|
+
end
|
126
|
+
|
127
|
+
def double_last_letter
|
128
|
+
last_piece = @pieces.pop
|
129
|
+
@pieces.push last_piece + last_piece[-1]
|
130
|
+
end
|
131
|
+
|
132
|
+
def join_pieces
|
133
|
+
@pieces.join.to_s
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FakeBritishToponym do
|
4
|
+
|
5
|
+
MANY = 10e3.to_i
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
expect(FakeBritishToponym).to be_truthy
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "options" do
|
12
|
+
|
13
|
+
describe "modifier" do
|
14
|
+
describe "when set to false" do
|
15
|
+
it "should never be more than one word or include punctuation" do
|
16
|
+
MANY.times do
|
17
|
+
toponym = FakeBritishToponym.new(modifier: false)
|
18
|
+
expect(toponym).to_not include " "
|
19
|
+
expect(toponym).to_not include "-"
|
20
|
+
expect(toponym).to_not include "'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not contain obvious errors" do
|
26
|
+
DOUBLE_CAPITAL_REGEX = /{[A-Z]{2}/
|
27
|
+
DOUBLE_NONALPHA_REGEX = /[^[:alpha:]]{2}/
|
28
|
+
|
29
|
+
MANY.times do
|
30
|
+
toponym = FakeBritishToponym.new(modifier: true)
|
31
|
+
[DOUBLE_CAPITAL_REGEX, DOUBLE_NONALPHA_REGEX].each do |regex|
|
32
|
+
expect(toponym).not_to match regex
|
33
|
+
end
|
34
|
+
[" -", "- ", " '", "' "].each do |bad_char_sequence|
|
35
|
+
expect(toponym).not_to include bad_char_sequence
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "min_syllables" do
|
42
|
+
it "should return words of roughly appropriate length" do
|
43
|
+
MANY.times do
|
44
|
+
length = rand(10)
|
45
|
+
toponym = FakeBritishToponym.new(min_syllables: length)
|
46
|
+
expect(toponym.length).to be > length * 2
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_british_toponym
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Generate place names that sound sorta British
|
56
|
+
email:
|
57
|
+
- alxndr+gem@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".hound.yml"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".ruby-gemset"
|
66
|
+
- ".ruby-version"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- Guardfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- fake_british_toponym.gemspec
|
74
|
+
- lib/fake_british_toponym.rb
|
75
|
+
- lib/fake_british_toponym/version.rb
|
76
|
+
- spec/fake_british_toponym_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- tasks/rspec.rake
|
79
|
+
homepage: https://github.com/alxndr/fake_british_toponym
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: A basic class which creates a string that sounds like it could be a town
|
103
|
+
in the British Isles.
|
104
|
+
test_files:
|
105
|
+
- spec/fake_british_toponym_spec.rb
|
106
|
+
- spec/spec_helper.rb
|