name-generator 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), 'name-generator/main')
2
+ require File.join(File.dirname(__FILE__), 'name-generator/version')
@@ -0,0 +1,62 @@
1
+ require 'active_support/core_ext/array/random_access'
2
+ require 'active_support/core_ext/string/inflections'
3
+
4
+ # This is a ruby-rewrite of "namegen.py" by Laust Rud Jacobsen (2010).
5
+
6
+ # From the original source-file (http://www.ailis.de/~k/archives/28-Name-Generator.html)
7
+ #
8
+ # This class generates names in the quality of the planet names used in
9
+ # the classic game Elite. The algorithm used in this class comes from
10
+ # the Mote project (http://mote.sourceforge.net/)
11
+
12
+
13
+ module NameGenerator
14
+ class Main
15
+
16
+ def next_name syllables = random_syllable_count
17
+ name = generate_name(syllables)
18
+ until sensible_name?(name)
19
+ name = generate_name(syllables)
20
+ end
21
+ name.titlecase
22
+ end
23
+
24
+ private
25
+ def generate_name syllables
26
+ name = (1...syllables).collect do
27
+ digraphs.sample
28
+ end
29
+ name << (digraphs + trigraphs).sample
30
+
31
+ name.join
32
+ end
33
+
34
+ def sensible_name? name
35
+ name !=~ /.*[aeiou]{3}.*/i # reject if at least three vowels in a row
36
+ end
37
+
38
+ def random_syllable_count
39
+ [2, 3, 4].sample
40
+ end
41
+
42
+ def digraphs
43
+ [
44
+ "a", "ac", "ad", "ar", "as", "at", "ax", "ba", "bi", "bo", "ce", "ci",
45
+ "co", "de", "di", "e", "ed", "en", "es", "ex", "fa", "fo", "ga", "ge",
46
+ "gi", "gu", "ha", "he", "in", "is", "it", "ju", "ka", "ky", "la", "le",
47
+ "le", "lo", "mi", "mo", "na", "ne", "ne", "ni", "no", "o", "ob", "oi",
48
+ "ol", "on", "or", "or", "os", "ou", "pe", "pi", "po", "qt", "re", "ro",
49
+ "sa", "se", "so", "ta", "te", "ti", "to", "tu", "ud", "um", "un", "us",
50
+ "ut", "va", "ve", "ve", "za", "zi"
51
+ ]
52
+ end
53
+
54
+ def trigraphs
55
+ [
56
+ "cla", "clu", "cra", "cre", "dre", "dro", "pha", "phi", "pho", "sha",
57
+ "she", "sta", "stu", "tha", "the", "thi", "thy", "tri"
58
+ ]
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ module NameGenerator
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'lib/name-generator'
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: name-generator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Laust Rud Jacobsen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-14 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ version: "3"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: rud@personal-it.dk
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/name-generator/main.rb
45
+ - lib/name-generator/version.rb
46
+ - lib/name-generator.rb
47
+ - spec/spec_helper.rb
48
+ has_rdoc: true
49
+ homepage:
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Easily generate game-compatible names
82
+ test_files:
83
+ - spec/spec_helper.rb