spicy-proton 1.0.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/lib/binary.rb +102 -0
- data/lib/corpus/adjectives.yaml +5139 -0
- data/lib/corpus/colors.yaml +137 -0
- data/lib/corpus/combined.bin +0 -0
- data/lib/corpus/nouns.yaml +11037 -0
- data/lib/files.rb +23 -0
- data/lib/spicy-proton.rb +80 -0
- metadata +66 -0
data/lib/files.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spicy
|
2
|
+
module Files
|
3
|
+
def self.dir
|
4
|
+
@@dir ||= File.join(File.dirname(__FILE__), 'corpus')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.adjectives
|
8
|
+
@@adjectives ||= File.join(dir, 'adjectives.yaml')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.nouns
|
12
|
+
@@nouns ||= File.join(dir, 'nouns.yaml')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.colors
|
16
|
+
@@colors ||= File.join(dir, 'colors.yaml')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.combined
|
20
|
+
@@combined ||= File.join(dir, 'combined.bin')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/spicy-proton.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'binary'
|
3
|
+
require 'files'
|
4
|
+
|
5
|
+
module Spicy
|
6
|
+
class Proton
|
7
|
+
def initialize
|
8
|
+
dir = File.dirname(__FILE__)
|
9
|
+
@adjectives = YAML.load_file(Files.adjectives)
|
10
|
+
@nouns = YAML.load_file(Files.nouns)
|
11
|
+
@colors = YAML.load_file(Files.colors)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.adjective
|
15
|
+
BinaryCorpus.use(&:adjective)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.noun
|
19
|
+
BinaryCorpus.use(&:noun)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.color
|
23
|
+
BinaryCorpus.use(&:color)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.pair(separator = '-')
|
27
|
+
BinaryCorpus.use do |b|
|
28
|
+
"#{b.adjective}#{separator}#{b.noun}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.format(format)
|
33
|
+
BinaryCorpus.use do |b|
|
34
|
+
self.format_with(b, format)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def adjective
|
39
|
+
random(adjectives)
|
40
|
+
end
|
41
|
+
|
42
|
+
def noun
|
43
|
+
random(nouns)
|
44
|
+
end
|
45
|
+
|
46
|
+
def color
|
47
|
+
random(colors)
|
48
|
+
end
|
49
|
+
|
50
|
+
def pair(separator = '-')
|
51
|
+
"#{self.adjective}#{separator}#{self.noun}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def format(format)
|
55
|
+
self.class.format_with(self, format)
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_accessor :adjectives, :nouns, :colors
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.format_with(source, format)
|
63
|
+
format.gsub(/%([anc])/) do
|
64
|
+
case $1
|
65
|
+
when 'a'
|
66
|
+
source.adjective
|
67
|
+
when 'n'
|
68
|
+
source.noun
|
69
|
+
when 'c'
|
70
|
+
source.color
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def random(set)
|
76
|
+
index = SecureRandom.random_number(set.count)
|
77
|
+
set[index]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spicy-proton
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Schmich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.10'
|
27
|
+
description: Generate a random adjective-noun pair.
|
28
|
+
email: schmch@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/binary.rb
|
36
|
+
- lib/corpus/adjectives.yaml
|
37
|
+
- lib/corpus/colors.yaml
|
38
|
+
- lib/corpus/combined.bin
|
39
|
+
- lib/corpus/nouns.yaml
|
40
|
+
- lib/files.rb
|
41
|
+
- lib/spicy-proton.rb
|
42
|
+
homepage: https://github.com/schmich/spicy-proton
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.9.3
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.6.8
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Generate a random adjective-noun pair.
|
66
|
+
test_files: []
|