namey 0.0.8 → 0.0.9

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f320c1ddb09bf1cc1c10663965949acafcce32d
4
+ data.tar.gz: a5f73434c7fe00392070f9d88b053aafddff3ad2
5
+ SHA512:
6
+ metadata.gz: a2b993038638bee8bbaebc224cdf9c0522f7ee64bf6d0983ad4a25d1ad6fe4012d73a6acb0fe250c40bfcfafb6a0d9530310a6f28540bb487dc7aa0044d67e73
7
+ data.tar.gz: f67f9d2b65f84d903c95826aa3627e7bd0873de0c0608cc595d22db8202e825f2ab9f2e23f37e7e05eb7d499f8db7ea10d21ab8f27541e4527ed647393e63a5e
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ config.ru
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-head
6
+ - jruby-19mode
7
+ # uncomment this line if your project needs to run something other than `rake`:
8
+ # script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in namey.gemspec
4
4
  gemspec
@@ -6,12 +6,9 @@ gemspec
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem 'simplecov', :require => false, :group => :test
10
-
11
9
  gem "shoulda", ">= 0"
12
10
  gem "rspec"
13
11
 
14
- gem "bundler", "~> 1.0.0"
15
12
  gem "watchr"
16
13
  end
17
14
 
@@ -19,7 +16,8 @@ end
19
16
  # couple extra gems for testing db connectivity
20
17
  #
21
18
  group :test do
19
+ gem 'simplecov', :require => false
22
20
  gem "sequel"
23
- gem "mysql"
24
- gem "sqlite3"
21
+ gem "sqlite3", :platform => :ruby
22
+ gem "jdbc-sqlite3", :platform => :jruby
25
23
  end
@@ -7,6 +7,8 @@ names. Since the database itself specifies the frequency of each name,
7
7
  you can get specify whether you want a common name, rare name, etc.
8
8
 
9
9
 
10
+ [![Build Status](https://travis-ci.org/muffinista/namey.png?branch=master)](https://travis-ci.org/muffinista/namey)
11
+
10
12
  ## Usage ##
11
13
 
12
14
  Using namey is pretty straightforward.
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  source 'http://gemcutter.org'
3
3
 
4
4
  gem "sinatra"
@@ -7,4 +7,6 @@ gem "mysql"
7
7
  gem "sequel"
8
8
  gem "json"
9
9
 
10
+ gem "shotgun"
11
+
10
12
  gem "namey"
@@ -3,6 +3,8 @@ require 'bundler'
3
3
 
4
4
  Bundler.require
5
5
 
6
+ # update this to point to your database
7
+ ENV['DATABASE_URL'] = "mysql://username@hostname/database"
8
+
6
9
  require './namey_app'
7
- #run NameyApp
8
10
  run Sinatra::Application
@@ -15,8 +15,19 @@ end
15
15
 
16
16
  # Establish the database connection; or, omit this and use the DATABASE_URL
17
17
  # environment variable as the connection string:
18
- set :database, 'mysql://username@hostname/database'
18
+ #set :database, 'mysql://username@hostname/database'
19
19
 
20
+
21
+ #
22
+ # migration for logging names
23
+ #
24
+ migration "create the generated_names table" do
25
+ database.create_table :generated_names do
26
+ primary_key :id
27
+ String :name, :null => false
28
+ timestamp :created_at, :null => false
29
+ end
30
+ end
20
31
 
21
32
  get '/' do
22
33
  # use index.haml for readme
@@ -24,7 +35,7 @@ get '/' do
24
35
  end
25
36
 
26
37
  get '/name.?:format?' do
27
- @generator = Namey::Generator.new(@database)
38
+ @generator = Namey::Generator.new(database)
28
39
 
29
40
  opts = {
30
41
  :frequency => :common
@@ -37,7 +48,6 @@ get '/name.?:format?' do
37
48
  end
38
49
 
39
50
  opts.delete(:type) if ! [:male, :female, :surname].include?(opts[:type])
40
- #opts[:type] = "both" if ! [:male, :female, :surname].include?(opts[:type])
41
51
 
42
52
  count = (params.delete(:count) || 1).to_i
43
53
  count = 10 if count > 10
@@ -45,10 +55,19 @@ get '/name.?:format?' do
45
55
  names = 1.upto(count).collect do
46
56
  @generator.generate(opts)
47
57
  end.compact
58
+
59
+ names.each do |name|
60
+ database[:generated_names].insert(:name => name)
61
+ end
48
62
 
49
63
  if params[:format] == "json"
50
64
  content_type :json, 'charset' => 'utf-8'
51
- JSON.generate names
65
+ tmp = JSON.generate names
66
+ if params[:callback]
67
+ "#{params[:callback]}(#{tmp});"
68
+ else
69
+ tmp
70
+ end
52
71
  else
53
72
  ["<ul>", names.collect { |n| "<li>#{n}</li>" }.join(" "), "</ul>"].join("")
54
73
  end
@@ -1,76 +1,88 @@
1
1
  /** namey */
2
2
  namey = {
3
- // jx -- http://www.openjs.com/scripts/jx/ -- V3.00.A
4
- jx:{getHTTPObject:function(){var A=false;if(typeof ActiveXObject!="undefined"){try{A=new ActiveXObject("Msxml2.XMLHTTP")}catch(C){try{A=new ActiveXObject("Microsoft.XMLHTTP")}catch(B){A=false}}}else{if(window.XMLHttpRequest){try{A=new XMLHttpRequest()}catch(C){A=false}}}return A},load:function(url,callback,format){var http=this.init();if(!http||!url){return }if(http.overrideMimeType){http.overrideMimeType("text/xml")}if(!format){var format="text"}format=format.toLowerCase();var now="uid="+new Date().getTime();url+=(url.indexOf("?")+1)?"&":"?";url+=now;http.open("GET",url,true);http.onreadystatechange=function(){if(http.readyState==4){if(http.status==200){var result="";if(http.responseText){result=http.responseText}if(format.charAt(0)=="j"){result=result.replace(/[\n\r]/g,"");result=eval("("+result+")")}if(callback){callback(result)}}else{if(error){error(http.status)}}}};http.send(null)},init:function(){return this.getHTTPObject()}},
5
3
 
6
- /**
7
- * API for namey random name generator. There's two basic ways to use it. First, just call namey.get with a callback:
8
- *
9
- * namey.get(function(n) { console.log(n); }); => ["John Clark"]
10
- *
11
- * The call returns an array because there's an option to request more than one random name. For example:
12
- *
13
- * namey.get({ count: 3, callback: function(n) { console.log(n); }}); ; => ["John Cook", "Ruth Fisher", "Donna Collins"]
14
- *
15
- * Here's the full list of parameters:
16
- *
17
- * count -- how many names you would like (default: 1)
18
- *
19
- * type -- what sort of name you want 'female', 'male', 'surname', or leave blank if you want both genders
20
- *
21
- * with_surname -- true/false, if you want surnames with the first
22
- * name. If false, you'll just get first names. Default is true.
23
- *
24
- * frequency -- 'common', 'rare', 'all' -- default is 'common'. This
25
- * picks a subset of names from the database -- common names are
26
- * names that occur frequently, rare is names that occur rarely.
27
- *
28
- * min_freq/max_freq -- specific values to get back a really
29
- * specific subset of the names db. values should be between 0 and
30
- * 100. You probably don't need this, but here's an example:
31
- * namey.get({ count: 3, min_freq: 30, max_freq: 50, callback: function(n) { console.log(n); }});
32
- * => ["Crystal Zimmerman", "Joshua Rivas", "Tina Bryan"]
33
- *
34
- * callback -- a function to do something with the data. The data
35
- * passed in will be an array of names -- use them wisely.
36
- *
37
- */
38
- get : function(options) {
39
- var callback;
40
- var tmp_params = [];
4
+ /*
5
+ * Lightweight JSONP fetcher
6
+ * Copyright 2010 Erik Karlsson. All rights reserved.
7
+ * BSD licensed
8
+ */
9
+ // Lightweight JSONP fetcher - www.nonobtrusive.com
10
+ jsonP:(function(){var a=0,c,f,b,d=this;function e(j){var i=document.createElement("script"),h=false;i.src=j;i.async=true;i.onload=i.onreadystatechange=function(){if(!h&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){h=true;i.onload=i.onreadystatechange=null;if(i&&i.parentNode){i.parentNode.removeChild(i)}}};if(!c){c=document.getElementsByTagName("head")[0]}c.appendChild(i)}function g(h,j,k){f="?";j=j||{};for(b in j){if(j.hasOwnProperty(b)){f+=encodeURIComponent(b)+"="+encodeURIComponent(j[b])+"&"}}var i="json"+(++a);d[i]=function(l){k(l);try{delete d[i]}catch(m){}d[i]=null;};e(h+f+"callback="+i);return i}return{get:g}}()),
41
11
 
42
- if ( typeof(options) == "function" ) {
43
- callback = options;
44
- }
45
- else if ( typeof(options) == "object" ) {
46
- callback = options.callback;
12
+ /**
13
+ * API for namey random name generator. There's two basic ways to use it. First, just call namey.get with a callback:
14
+ *
15
+ * namey.get(function(n) { console.log(n); }); => ["John Clark"]
16
+ *
17
+ * The call returns an array because there's an option to request more than one random name. For example:
18
+ *
19
+ * namey.get({ count: 3, callback: function(n) { console.log(n); }}); ; => ["John Cook", "Ruth Fisher", "Donna Collins"]
20
+ *
21
+ * Here's the full list of parameters:
22
+ *
23
+ * count -- how many names you would like (default: 1)
24
+ *
25
+ * type -- what sort of name you want 'female', 'male', 'surname', or leave blank if you want both genders
26
+ *
27
+ * with_surname -- true/false, if you want surnames with the first
28
+ * name. If false, you'll just get first names. Default is true.
29
+ *
30
+ * frequency -- 'common', 'rare', 'all' -- default is 'common'. This
31
+ * picks a subset of names from the database -- common names are
32
+ * names that occur frequently, rare is names that occur rarely.
33
+ *
34
+ * min_freq/max_freq -- specific values to get back a really
35
+ * specific subset of the names db. values should be between 0 and
36
+ * 100. You probably don't need this, but here's an example:
37
+ * namey.get({ count: 3, min_freq: 30, max_freq: 50, callback: function(n) { console.log(n); }});
38
+ * => ["Crystal Zimmerman", "Joshua Rivas", "Tina Bryan"]
39
+ *
40
+ * callback -- a function to do something with the data. The data
41
+ * passed in will be an array of names -- use them wisely.
42
+ *
43
+ */
44
+ get : function(options) {
45
+ var callback;
46
+ var tmp_params = [];
47
47
 
48
- if ( typeof(options.count) == "undefined" ) {
49
- options.count = 1;
50
- }
51
- tmp_params.push("count=" + options.count);
48
+ if ( typeof(options) == "function" ) {
49
+ callback = options;
50
+ }
51
+ else if ( typeof(options) == "object" ) {
52
+ callback = options.callback;
52
53
 
53
- if ( typeof(options.type) != "undefined" && options.type != "both" ) {
54
- tmp_params.push("type=" + options.type);
55
- };
54
+ if ( typeof(options.host) === "undefined" ) {
55
+ options.host = "namey.muffinlabs.com";
56
+ }
56
57
 
57
- if ( options.type != "surname" && typeof(options.with_surname) != "undefined" ) {
58
- tmp_params.push("with_surname=" + options.with_surname);
59
- }
60
- if ( options.min_freq ) {
61
- tmp_params.push("min_freq=" + options.min_freq);
62
- tmp_params.push("max_freq=" + options.max_freq);
63
- }
64
- else if ( typeof(options.frequency) != "undefined" ) {
65
- tmp_params.push("frequency=" + options.frequency);
66
- }
67
- }
58
+ if ( typeof(options.count) == "undefined" ) {
59
+ options.count = 1;
60
+ }
61
+ tmp_params.push("count=" + options.count);
68
62
 
69
- this.jx.load('/name.json?' + tmp_params.join("&"), function(d) {
70
- var tmp = eval('(' + d + ')');
71
- if ( typeof(callback) == "function" ) {
72
- callback(tmp);
73
- }
74
- });
75
- }
63
+ if ( typeof(options.type) != "undefined" && options.type != "both" ) {
64
+ tmp_params.push("type=" + options.type);
65
+ };
66
+
67
+ if ( options.type != "surname" && typeof(options.with_surname) != "undefined" ) {
68
+ tmp_params.push("with_surname=" + options.with_surname);
69
+ }
70
+ if ( options.min_freq ) {
71
+ tmp_params.push("min_freq=" + options.min_freq);
72
+ tmp_params.push("max_freq=" + options.max_freq);
73
+ }
74
+ else if ( typeof(options.frequency) != "undefined" ) {
75
+ tmp_params.push("frequency=" + options.frequency);
76
+ }
77
+ }
78
+
79
+ this.jsonP.get('//' + options.host + '/name.json', tmp_params, function(d) {
80
+ if ( typeof(callback) == "function" ) {
81
+ callback(d);
82
+ }
83
+ else {
84
+ console.log(d);
85
+ }
86
+ });
87
+ }
76
88
  }
@@ -15,7 +15,7 @@ puts "Load data to #{dest}"
15
15
  #@parser.load_female_names("data/dist.female.first")
16
16
  #@parser.load_surnames("data/dist.all.last")
17
17
 
18
- base_url = "http://www.census.gov/genealogy/names"
18
+ base_url = "http://www.census.gov/genealogy/www/data/1990surnames"
19
19
  @parser.load_male_names("#{base_url}/dist.male.first")
20
20
  @parser.load_female_names("#{base_url}/dist.female.first")
21
21
  @parser.load_surnames("#{base_url}/dist.all.last")
@@ -1,6 +1,6 @@
1
1
  module Namey
2
2
  def self.db_path
3
- @@db_path ||= "sqlite://#{File.join(self.libdir, "..", "data", "names.db")}"
3
+ @@db_path ||= "#{'jdbc:' if RUBY_PLATFORM == 'java'}sqlite://" + File.join(self.libdir, "..", "data", "names.db")
4
4
  end
5
5
  def self.db_path=(x)
6
6
  @@db_path = x
@@ -1,4 +1,4 @@
1
1
  module Namey
2
2
  NAME = "namey"
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
@@ -5,7 +5,6 @@ require "namey/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "namey"
7
7
  s.version = Namey::VERSION
8
- s.platform = Gem::Platform::RUBY
9
8
  s.authors = ["Colin Mitchell"]
10
9
  s.email = ["colin@muffinlabs.com"]
11
10
  s.homepage = "https://github.com/muffinista/namey"
@@ -19,26 +18,27 @@ Gem::Specification.new do |s|
19
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
19
  s.require_paths = ["lib"]
21
20
 
22
- if s.respond_to? :specification_version then
23
- s.specification_version = 3
24
-
25
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<sequel>, [">= 0"])
27
- s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
28
- s.add_development_dependency(%q<shoulda>, [">= 0"])
29
- s.add_development_dependency(%q<yard>, [">= 0"])
30
- else
31
- s.add_dependency(%q<sequel>, [">= 0"])
32
- s.add_dependency(%q<sqlite3>, [">= 0"])
33
- s.add_dependency(%q<shoulda>, [">= 0"])
34
- s.add_dependency(%q<yard>, [">= 0"])
35
- end
21
+ if RUBY_PLATFORM == "java"
22
+ s.platform = "java"
23
+ sqlite = "jdbc-sqlite3"
36
24
  else
37
- s.add_dependency(%q<sequel>, [">= 0"])
38
- s.add_dependency(%q<sqlite3>, [">= 0"])
39
- s.add_dependency(%q<shoulda>, [">= 0"])
40
- s.add_dependency(%q<yard>, [">= 0"])
25
+ s.platform = Gem::Platform::RUBY
26
+ sqlite = "sqlite3"
41
27
  end
28
+
29
+ if RUBY_VERSION < "1.9"
30
+ spec.add_dependency "activesupport", "~> 3.0.11"
31
+ end
32
+
33
+ #s.specification_version = 3
34
+
35
+ s.add_development_dependency(%q<rake>, [">= 0"])
36
+ s.add_development_dependency(%q<rspec>, [">= 2.12.0"])
37
+
38
+ s.add_runtime_dependency(%q<sequel>, [">= 0"])
39
+ s.add_runtime_dependency(sqlite, [">= 0"])
40
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
41
+ s.add_development_dependency(%q<yard>, [">= 0"])
42
42
  end
43
43
 
44
44
 
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Namey::Generator" do
4
4
  before(:each) do
5
- @uri = "sqlite:/"
5
+ @uri = "#{'jdbc:' if RUBY_PLATFORM == 'java'}sqlite:/"
6
6
  @gen = Namey::Generator.new(@uri)
7
7
  end
8
8
 
@@ -10,7 +10,6 @@ Bundler.require
10
10
  #require 'chatterbot'
11
11
 
12
12
  require 'tempfile'
13
- require 'sqlite3'
14
13
 
15
14
 
16
15
  # Requires supporting files with custom matchers and macros, etc,
metadata CHANGED
@@ -1,60 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 0.0.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Colin Mitchell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-11-15 00:00:00.000000000Z
11
+ date: 2013-11-18 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.0
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: sequel
16
- requirement: &9641500 !ruby/object:Gem::Requirement
17
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
18
44
  requirements:
19
- - - ! '>='
45
+ - - '>='
20
46
  - !ruby/object:Gem::Version
21
47
  version: '0'
22
48
  type: :runtime
23
49
  prerelease: false
24
- version_requirements: *9641500
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
25
55
  - !ruby/object:Gem::Dependency
26
56
  name: sqlite3
27
- requirement: &9641000 !ruby/object:Gem::Requirement
28
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
29
58
  requirements:
30
- - - ! '>='
59
+ - - '>='
31
60
  - !ruby/object:Gem::Version
32
61
  version: '0'
33
62
  type: :runtime
34
63
  prerelease: false
35
- version_requirements: *9641000
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
36
69
  - !ruby/object:Gem::Dependency
37
70
  name: shoulda
38
- requirement: &9640520 !ruby/object:Gem::Requirement
39
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
40
72
  requirements:
41
- - - ! '>='
73
+ - - '>='
42
74
  - !ruby/object:Gem::Version
43
75
  version: '0'
44
76
  type: :development
45
77
  prerelease: false
46
- version_requirements: *9640520
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
47
83
  - !ruby/object:Gem::Dependency
48
84
  name: yard
49
- requirement: &9640040 !ruby/object:Gem::Requirement
50
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
51
86
  requirements:
52
- - - ! '>='
87
+ - - '>='
53
88
  - !ruby/object:Gem::Version
54
89
  version: '0'
55
90
  type: :development
56
91
  prerelease: false
57
- version_requirements: *9640040
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
58
97
  description: Simple name generator, which can generate male/female names based on
59
98
  US Census Data
60
99
  email:
@@ -66,11 +105,12 @@ extensions: []
66
105
  extra_rdoc_files: []
67
106
  files:
68
107
  - .gitignore
108
+ - .travis.yml
69
109
  - Gemfile
70
110
  - README.markdown
71
111
  - Rakefile
72
112
  - api/Gemfile
73
- - api/config.ru
113
+ - api/config.ru.example
74
114
  - api/namey_app.rb
75
115
  - api/public/LICENSE
76
116
  - api/public/Makefile
@@ -142,27 +182,26 @@ files:
142
182
  - spec/spec_helper.rb
143
183
  homepage: https://github.com/muffinista/namey
144
184
  licenses: []
185
+ metadata: {}
145
186
  post_install_message:
146
187
  rdoc_options: []
147
188
  require_paths:
148
189
  - lib
149
190
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
191
  requirements:
152
- - - ! '>='
192
+ - - '>='
153
193
  - !ruby/object:Gem::Version
154
194
  version: '0'
155
195
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
196
  requirements:
158
- - - ! '>='
197
+ - - '>='
159
198
  - !ruby/object:Gem::Version
160
199
  version: '0'
161
200
  requirements: []
162
201
  rubyforge_project: namey
163
- rubygems_version: 1.8.6
202
+ rubygems_version: 2.0.3
164
203
  signing_key:
165
- specification_version: 3
204
+ specification_version: 4
166
205
  summary: Simple name generator based on US Census Data
167
206
  test_files: []
168
207
  has_rdoc: