teebo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b39c312308355f0fe6943109ae6356a52cc0f1cc
4
- data.tar.gz: c9c8fc4e0db8f9228b4d4d512c716d8359d52c05
3
+ metadata.gz: c08b25e131c864ae6ff3222cf665dc2359ad7849
4
+ data.tar.gz: 7533533ef81909ca782e0d3acfb53dc616592946
5
5
  SHA512:
6
- metadata.gz: be7143b79ea1c277f7b0f4ee92ab57cc21b04ea96e92de23cccbf3644ec290f0f896f25a2fd3ac29bd4828a9c477d95074d5c2642f58821f6bc47ae4d0d7c4e0
7
- data.tar.gz: 19ce9d17ae23fd916a8e5f528a0bda3a61b2fc17fe18dccec909bbc5196676072daa38294f3a1262ce9cbb69816c074d296f06b0632b553dd1edf36c2f3b71a7
6
+ metadata.gz: 61eff7754a95eea9831e654aeee41539062d2b3b77efbf97e684ce0f3248bb196d1a236c5593a85edb25b13873dedbf3049aeb8ab5f0a714cd613ab245e64da1
7
+ data.tar.gz: 4f96222ca2bfe0dafa081e3cc34f7dfe6c6590db374fd0e82f0c8cc790ea7058d3b79feb6e8b4f410c9a2c71351428e20f6023ba3555167f40897cc31d55f615
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
- @@database = SQLite3::Database.new "lib/data/seed-data.db"
10
- @@database.results_as_hash = true
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
- return @@database.execute(find_count, sex)[0][0]
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
- rand = rand(count)
30
- return @@database.execute(find_range_query, sex, rand)[0]['name']
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teebo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russ Taylor