codename 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +17 -0
- data/README.txt +80 -0
- data/Rakefile +12 -0
- data/bin/codename +37 -0
- data/lib/codename.rb +9 -0
- data/lib/codename/generator.rb +18 -0
- data/lib/codename/lister.rb +10 -0
- data/lib/codename/lister/base_lister.rb +38 -0
- data/lib/codename/lister/colors_lister.rb +24 -0
- data/lib/codename/lister/cyclones_lister.rb +28 -0
- data/lib/codename/lister/elements_lister.rb +24 -0
- data/lib/codename/lister/factory.rb +47 -0
- data/lib/codename/lister/random_lister.rb +18 -0
- data/lib/codename/lister/stars_lister.rb +24 -0
- metadata +139 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
bin/codename
|
7
|
+
lib/codename.rb
|
8
|
+
lib/codename/generator.rb
|
9
|
+
lib/codename/lister.rb
|
10
|
+
lib/codename/lister/factory.rb
|
11
|
+
lib/codename/lister/base_lister.rb
|
12
|
+
lib/codename/lister/colors_lister.rb
|
13
|
+
lib/codename/lister/cyclones_lister.rb
|
14
|
+
lib/codename/lister/elements_lister.rb
|
15
|
+
lib/codename/lister/random_lister.rb
|
16
|
+
lib/codename/lister/stars_lister.rb
|
17
|
+
|
data/README.txt
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= codename
|
2
|
+
|
3
|
+
home :: https://github.com/siuying/codename
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Codename gem randomly generate codename based on list of sources.
|
8
|
+
|
9
|
+
Supported sources:
|
10
|
+
|
11
|
+
* stars - Western constellation names
|
12
|
+
* elements - Elements names
|
13
|
+
* colors - Color names
|
14
|
+
* cyclones - Names of tropical cyclones
|
15
|
+
* random - Random numbers (00000 - 99999)
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
|
19
|
+
You may generate names by "generate" command
|
20
|
+
|
21
|
+
% codename generate source [more_source]...
|
22
|
+
|
23
|
+
example:
|
24
|
+
|
25
|
+
% codename generate stars cyclones
|
26
|
+
orion-sanvu
|
27
|
+
aquarius-kujira
|
28
|
+
reticulum-washi
|
29
|
+
vulpecula-nari
|
30
|
+
draco-meari
|
31
|
+
lacerta-toraji
|
32
|
+
antlia-sepat
|
33
|
+
equuleus-meranti
|
34
|
+
crater-lekima
|
35
|
+
circinus-mindulle
|
36
|
+
|
37
|
+
You may find list of supported source by "help" commands:
|
38
|
+
|
39
|
+
% codename help
|
40
|
+
Usage: codename generate list_name [more_list_name]...
|
41
|
+
Usage: codename help
|
42
|
+
list names:
|
43
|
+
stars - Western constellation names
|
44
|
+
elements - Elements names
|
45
|
+
colors - Colour names
|
46
|
+
cyclones - Names of tropical cyclones
|
47
|
+
random - Random numbers (00000 - 99999)
|
48
|
+
|
49
|
+
== REQUIREMENTS:
|
50
|
+
|
51
|
+
* nokogiri
|
52
|
+
|
53
|
+
== INSTALL:
|
54
|
+
|
55
|
+
* sudo gem install codename
|
56
|
+
|
57
|
+
== LICENSE:
|
58
|
+
|
59
|
+
(The MIT License)
|
60
|
+
|
61
|
+
Copyright (c) 2011 Francis Chong
|
62
|
+
|
63
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
64
|
+
a copy of this software and associated documentation files (the
|
65
|
+
'Software'), to deal in the Software without restriction, including
|
66
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
67
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
68
|
+
permit persons to whom the Software is furnished to do so, subject to
|
69
|
+
the following conditions:
|
70
|
+
|
71
|
+
The above copyright notice and this permission notice shall be
|
72
|
+
included in all copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
75
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
76
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
77
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
78
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
79
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
80
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/codename
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'codename'
|
5
|
+
|
6
|
+
def help(show_help=false)
|
7
|
+
puts "Usage: codename generate list_name [more_list_name]..."
|
8
|
+
puts "Usage: codename help" if show_help
|
9
|
+
|
10
|
+
f = Codename::Lister::Factory
|
11
|
+
puts "list names: "
|
12
|
+
puts f.instance.info.collect {|info| "\t#{info[0].ljust(15)}- #{info[1]}" }.join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
command = ARGV.shift
|
16
|
+
case (command)
|
17
|
+
when "help", "h"
|
18
|
+
help
|
19
|
+
|
20
|
+
when "generate", "g"
|
21
|
+
if ARGV.size > 0
|
22
|
+
g = Codename::Generator.new(*ARGV)
|
23
|
+
10.times do
|
24
|
+
puts g.generate
|
25
|
+
end
|
26
|
+
|
27
|
+
else
|
28
|
+
puts "codename: missing names"
|
29
|
+
puts "Usage: codename generate list_name [more_list_name]..."
|
30
|
+
puts "\nTo get names of all supported list, try \`codename help\`"
|
31
|
+
end
|
32
|
+
|
33
|
+
else
|
34
|
+
puts "codename: missing command #{command}"
|
35
|
+
help(true)
|
36
|
+
|
37
|
+
end
|
data/lib/codename.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Codename
|
2
|
+
class Generator
|
3
|
+
attr_reader :listers
|
4
|
+
|
5
|
+
def initialize(*names)
|
6
|
+
@listers = []
|
7
|
+
names.each do |name|
|
8
|
+
@listers << ::Codename::Lister::Factory.instance.lister(name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
@listers.collect do |lister|
|
14
|
+
lister.random
|
15
|
+
end.join(" ").downcase.gsub(" ", "-")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
path = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$:.unshift(path) unless $:.include?(path)
|
3
|
+
|
4
|
+
require 'lister/factory'
|
5
|
+
require 'lister/base_lister'
|
6
|
+
require 'lister/stars_lister'
|
7
|
+
require 'lister/elements_lister'
|
8
|
+
require 'lister/colors_lister'
|
9
|
+
require 'lister/cyclones_lister'
|
10
|
+
require 'lister/random_lister'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Codename::Lister
|
4
|
+
class BaseLister
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
# Public: list names
|
8
|
+
#
|
9
|
+
# Returns array of names
|
10
|
+
def list
|
11
|
+
raise "Implement me in subclass"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Public: Get an random item from the lister
|
15
|
+
#
|
16
|
+
# Returns random item from the list
|
17
|
+
def random
|
18
|
+
@__list ||= list
|
19
|
+
@__list[rand(@__list.size)]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Get the size of the list contains
|
23
|
+
#
|
24
|
+
# Returns size of the list
|
25
|
+
def size
|
26
|
+
@__list ||= list
|
27
|
+
@__list.size
|
28
|
+
end
|
29
|
+
|
30
|
+
def name
|
31
|
+
"base"
|
32
|
+
end
|
33
|
+
|
34
|
+
def description
|
35
|
+
"description of the lister"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Codename::Lister
|
6
|
+
class ColorsLister < BaseLister
|
7
|
+
URL = "http://www.colordic.org/y/"
|
8
|
+
|
9
|
+
def list
|
10
|
+
doc = Nokogiri::HTML(open(URL))
|
11
|
+
doc.css("table.colortable td a span").collect { |node| node.text }
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
"colors"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"Color names"
|
20
|
+
end
|
21
|
+
|
22
|
+
Factory.instance.register(ColorsLister)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Codename::Lister
|
6
|
+
class CyclonesLister < BaseLister
|
7
|
+
URL = "http://www.jma.go.jp/jma/jma-eng/jma-center/rsmc-hp-pub-eg/tyname.html"
|
8
|
+
|
9
|
+
def list
|
10
|
+
doc = Nokogiri::HTML(open(URL))
|
11
|
+
doc.xpath("/html/body/table[3]/tr").collect do |rows|
|
12
|
+
columns = rows.css("td")
|
13
|
+
columns.shift
|
14
|
+
columns.collect {|c| c.text }
|
15
|
+
end.flatten.select {|name| name !=~ /column/}
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
"cyclones"
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
"Names of tropical cyclones"
|
24
|
+
end
|
25
|
+
|
26
|
+
Factory.instance.register(CyclonesLister)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Codename::Lister
|
6
|
+
class ElementsLister < BaseLister
|
7
|
+
URL = "http://en.wikipedia.org/wiki/List_of_elements"
|
8
|
+
|
9
|
+
def list
|
10
|
+
doc = Nokogiri::HTML(open(URL))
|
11
|
+
doc.css("table.wikitable tr > td[3] > a[1]").collect { |node| node.text }
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
"elements"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"Elements names"
|
20
|
+
end
|
21
|
+
|
22
|
+
Factory.instance.register(ElementsLister)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Codename::Lister
|
4
|
+
class Factory
|
5
|
+
include Singleton
|
6
|
+
attr_reader :listers
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@listers = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: Register a lister
|
13
|
+
#
|
14
|
+
# clazz - a lister class to be register
|
15
|
+
#
|
16
|
+
# Returns self
|
17
|
+
def register(clazz)
|
18
|
+
@listers << clazz.instance
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Find lister by name
|
23
|
+
#
|
24
|
+
# name - string, name of the lister
|
25
|
+
#
|
26
|
+
# Returns lister class
|
27
|
+
def lister(name)
|
28
|
+
lister_class = @listers.find do |lister|
|
29
|
+
lister.name == name
|
30
|
+
end
|
31
|
+
|
32
|
+
if lister_class
|
33
|
+
lister_class
|
34
|
+
else
|
35
|
+
raise "Cannot find lister '#{name}'"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Public: get information of supported name lists
|
41
|
+
#
|
42
|
+
# Returns array of array contains name and description of lists
|
43
|
+
def info
|
44
|
+
@listers.collect {|l| [l.name, l.description] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Codename::Lister
|
2
|
+
# Return random number 00001 - 99999
|
3
|
+
class RandomLister < BaseLister
|
4
|
+
def list
|
5
|
+
(0..99999).to_a.collect{|a| ["%05d" % a]}
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
"random"
|
10
|
+
end
|
11
|
+
|
12
|
+
def description
|
13
|
+
"Random numbers (00000 - 99999)"
|
14
|
+
end
|
15
|
+
|
16
|
+
Factory.instance.register(RandomLister)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Codename::Lister
|
6
|
+
class StarsLister < BaseLister
|
7
|
+
URL = "http://en.wikipedia.org/wiki/List_of_constellations"
|
8
|
+
|
9
|
+
def list
|
10
|
+
doc = Nokogiri::HTML(open(URL))
|
11
|
+
doc.css("table.wikitable tr > td[1] > a[1]").collect { |node| node.text }
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
"stars"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"Western constellation names"
|
20
|
+
end
|
21
|
+
|
22
|
+
Factory.instance.register(StarsLister)
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codename
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Francis Chong
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nokogiri
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 0
|
33
|
+
version: 1.4.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hoe
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 27
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 12
|
48
|
+
version: "2.12"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rdoc
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 19
|
60
|
+
segments:
|
61
|
+
- 3
|
62
|
+
- 10
|
63
|
+
version: "3.10"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: |-
|
67
|
+
Codename gem randomly generate codename based on list of sources.
|
68
|
+
|
69
|
+
Supported sources:
|
70
|
+
|
71
|
+
* stars - Western constellation names
|
72
|
+
* elements - Elements names
|
73
|
+
* colors - Color names
|
74
|
+
* cyclones - Names of tropical cyclones
|
75
|
+
* random - Random numbers (00000 - 99999)
|
76
|
+
email:
|
77
|
+
- francis@ignition.hk
|
78
|
+
executables:
|
79
|
+
- codename
|
80
|
+
extensions: []
|
81
|
+
|
82
|
+
extra_rdoc_files:
|
83
|
+
- History.txt
|
84
|
+
- Manifest.txt
|
85
|
+
- README.txt
|
86
|
+
files:
|
87
|
+
- .autotest
|
88
|
+
- History.txt
|
89
|
+
- Manifest.txt
|
90
|
+
- README.txt
|
91
|
+
- Rakefile
|
92
|
+
- bin/codename
|
93
|
+
- lib/codename.rb
|
94
|
+
- lib/codename/generator.rb
|
95
|
+
- lib/codename/lister.rb
|
96
|
+
- lib/codename/lister/factory.rb
|
97
|
+
- lib/codename/lister/base_lister.rb
|
98
|
+
- lib/codename/lister/colors_lister.rb
|
99
|
+
- lib/codename/lister/cyclones_lister.rb
|
100
|
+
- lib/codename/lister/elements_lister.rb
|
101
|
+
- lib/codename/lister/random_lister.rb
|
102
|
+
- lib/codename/lister/stars_lister.rb
|
103
|
+
- .gemtest
|
104
|
+
homepage: https://github.com/siuying/codename
|
105
|
+
licenses: []
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- --main
|
110
|
+
- README.txt
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
131
|
+
requirements: []
|
132
|
+
|
133
|
+
rubyforge_project: codename
|
134
|
+
rubygems_version: 1.8.10
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Codename gem randomly generate codename based on list of sources
|
138
|
+
test_files: []
|
139
|
+
|