teebo 0.0.0 → 0.0.2

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: 15f0a0f9002a98fa710f927da782c414b2ecb578
4
- data.tar.gz: 4fc754efaf6db4de5ad19078cbd02c568cebc172
3
+ metadata.gz: b39c312308355f0fe6943109ae6356a52cc0f1cc
4
+ data.tar.gz: c9c8fc4e0db8f9228b4d4d512c716d8359d52c05
5
5
  SHA512:
6
- metadata.gz: 9a9183319cc65b53712e36e2e3d0afbf0d56020b2b09562c260608277432e18ce43cb4486909f46688a5d6a96e68bd7e7764384719df215f0994a0a309601843
7
- data.tar.gz: 094c2c8187768e7a7ae63032461a87aa5079d2e26545b49458ddaa4d8dcebcb6c425a58fb5122b96de7a2a5f9fd10ecf4693c265bba7f993d12d1cf0156951d1
6
+ metadata.gz: be7143b79ea1c277f7b0f4ee92ab57cc21b04ea96e92de23cccbf3644ec290f0f896f25a2fd3ac29bd4828a9c477d95074d5c2642f58821f6bc47ae4d0d7c4e0
7
+ data.tar.gz: 19ce9d17ae23fd916a8e5f528a0bda3a61b2fc17fe18dccec909bbc5196676072daa38294f3a1262ce9cbb69816c074d296f06b0632b553dd1edf36c2f3b71a7
Binary file
@@ -1,5 +1,38 @@
1
- class Teebo
2
- def self.initial
3
- puts "Hello, world!"
1
+ require 'sqlite3'
2
+
3
+ module Teebo
4
+
5
+ class Base
6
+
7
+ def initialize
8
+ # Initialize the database
9
+ @@database = SQLite3::Database.new "lib/data/seed-data.db"
10
+ @@database.results_as_hash = true
11
+ end
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
4
35
  end
5
36
  end
37
+
38
+ require 'teebo/name'
@@ -0,0 +1,33 @@
1
+ module Teebo
2
+ #
3
+ # Generates names in accordance with their frequency in the United States
4
+ # population.
5
+ #
6
+ class Name < Base
7
+
8
+ #
9
+ # Finds the total count for the number of names in the database.
10
+ #
11
+ def sum_count sex
12
+ find_count = <<-SQL
13
+ select sum(count) from 'given_names' where sex = ?
14
+ SQL
15
+ return @@database.execute(find_count, sex)[0][0]
16
+ end
17
+
18
+ #
19
+ # Selects a random (weighted) given name from the database.
20
+ #
21
+ def given_name sex
22
+ find_range_query = <<-SQL
23
+ select * from given_names where sex = ?
24
+ and (count_to - ?) >= 0
25
+ order by id limit 1
26
+ SQL
27
+
28
+ count = sum_count sex
29
+ rand = rand(count)
30
+ return @@database.execute(find_range_query, sex, rand)[0]['name']
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,23 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teebo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russ Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.9
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.9
13
33
  description: Contains basic functionality for data generation.
14
34
  email: russ@russt.me
15
35
  executables: []
16
36
  extensions: []
17
37
  extra_rdoc_files: []
18
38
  files:
39
+ - lib/data/seed-data.db
19
40
  - lib/teebo.rb
20
- homepage: http://rubygems.org/gems/teebo
41
+ - lib/teebo/name.rb
42
+ homepage: http://github.com/russtaylor/teebo
21
43
  licenses:
22
44
  - MIT
23
45
  metadata: {}