teebo 0.0.2 → 0.0.3
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 +4 -4
- data/lib/data/seed-data.db +0 -0
- data/lib/teebo.rb +2 -24
- data/lib/teebo/name.rb +44 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c08b25e131c864ae6ff3222cf665dc2359ad7849
|
4
|
+
data.tar.gz: 7533533ef81909ca782e0d3acfb53dc616592946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61eff7754a95eea9831e654aeee41539062d2b3b77efbf97e684ce0f3248bb196d1a236c5593a85edb25b13873dedbf3049aeb8ab5f0a714cd613ab245e64da1
|
7
|
+
data.tar.gz: 4f96222ca2bfe0dafa081e3cc34f7dfe6c6590db374fd0e82f0c8cc790ea7058d3b79feb6e8b4f410c9a2c71351428e20f6023ba3555167f40897cc31d55f615
|
data/lib/data/seed-data.db
CHANGED
Binary file
|
data/lib/teebo.rb
CHANGED
@@ -6,32 +6,10 @@ module Teebo
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
# Initialize the database
|
9
|
-
|
10
|
-
|
9
|
+
@database = SQLite3::Database.new "lib/data/seed-data.db"
|
10
|
+
@database.results_as_hash = true
|
11
11
|
end
|
12
12
|
|
13
|
-
def weight
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def update_sum_count
|
18
|
-
sexes = ['M', 'F']
|
19
|
-
sexes.each do |sex|
|
20
|
-
get_rows = <<-SQL
|
21
|
-
select * from given_names where sex = ?
|
22
|
-
SQL
|
23
|
-
|
24
|
-
put_count_to = <<-SQL
|
25
|
-
update given_names set count_to = ? where id = ?
|
26
|
-
SQL
|
27
|
-
|
28
|
-
count = 0
|
29
|
-
@database.execute(get_rows, sex) do |row|
|
30
|
-
count += row['count']
|
31
|
-
database.execute(put_count_to, count, row[0])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
13
|
end
|
36
14
|
end
|
37
15
|
|
data/lib/teebo/name.rb
CHANGED
@@ -5,6 +5,34 @@ module Teebo
|
|
5
5
|
#
|
6
6
|
class Name < Base
|
7
7
|
|
8
|
+
#
|
9
|
+
# Picks a random first & last name, selecting a random gender if it's not
|
10
|
+
# specified.
|
11
|
+
#
|
12
|
+
def name sex=nil
|
13
|
+
if sex.nil?
|
14
|
+
sex = ['M', 'F'].sample
|
15
|
+
end
|
16
|
+
given_name(sex) + " " + surname
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Generates a normal full name, including a middle name.
|
21
|
+
#
|
22
|
+
# For now, this is fairly sloppy, as the probability that a middle name will
|
23
|
+
# simply be another given name of the same gender is almost certainly less
|
24
|
+
# than 100%.
|
25
|
+
#
|
26
|
+
# TODO: Make this take into account different probablities of different
|
27
|
+
# types of middle names.
|
28
|
+
#
|
29
|
+
def full_name sex=nil
|
30
|
+
if sex.nil?
|
31
|
+
sex = ['M', 'F'].sample
|
32
|
+
end
|
33
|
+
given_name(sex) + " " + given_name(sex) + " " + surname
|
34
|
+
end
|
35
|
+
|
8
36
|
#
|
9
37
|
# Finds the total count for the number of names in the database.
|
10
38
|
#
|
@@ -12,7 +40,7 @@ module Teebo
|
|
12
40
|
find_count = <<-SQL
|
13
41
|
select sum(count) from 'given_names' where sex = ?
|
14
42
|
SQL
|
15
|
-
|
43
|
+
@database.execute(find_count, sex)[0][0]
|
16
44
|
end
|
17
45
|
|
18
46
|
#
|
@@ -26,8 +54,21 @@ module Teebo
|
|
26
54
|
SQL
|
27
55
|
|
28
56
|
count = sum_count sex
|
29
|
-
|
30
|
-
|
57
|
+
selection = rand(count)
|
58
|
+
@database.execute(find_range_query, sex, selection)[0]['name']
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Selects a random (weighted) surname from the database.
|
63
|
+
#
|
64
|
+
def surname
|
65
|
+
find_range_query = <<-SQL
|
66
|
+
select * from surnames where (count_to - ?) >= 0 order by id limit 1
|
67
|
+
SQL
|
68
|
+
|
69
|
+
count = @database.execute('select sum(count) from surnames')[0][0]
|
70
|
+
selection = rand(count)
|
71
|
+
@database.execute(find_range_query, selection)[0]['name']
|
31
72
|
end
|
32
73
|
end
|
33
74
|
end
|