trip_phrase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/UNLICENSE +24 -0
- data/bin/trip_phrase +14 -0
- data/data/adj.txt +20748 -0
- data/data/adv.txt +3766 -0
- data/data/article.txt +13 -0
- data/data/noun.txt +57387 -0
- data/data/verb.txt +8700 -0
- data/lib/trip_phrase.rb +10 -0
- data/lib/trip_phrase/phrase_generator.rb +43 -0
- data/lib/trip_phrase/version.rb +3 -0
- data/lib/trip_phrase/word_type.rb +41 -0
- data/trip_phrase.gemspec +18 -0
- metadata +63 -0
data/lib/trip_phrase.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module TripPhrase
|
4
|
+
|
5
|
+
class PhraseGenerator
|
6
|
+
attr_reader :salt, :password
|
7
|
+
|
8
|
+
TEMPLATES = [
|
9
|
+
%w(verb article adj noun),
|
10
|
+
%w(article adj adj noun),
|
11
|
+
%w(article adv adj noun),
|
12
|
+
%w(adv verb article noun)
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(salt, password)
|
16
|
+
@salt = salt
|
17
|
+
@password = password
|
18
|
+
end
|
19
|
+
|
20
|
+
def next_key
|
21
|
+
@key ||= Digest::MD5.hexdigest(salt + password)
|
22
|
+
@key = @key[-1] + @key[0..-2]
|
23
|
+
@key.hex
|
24
|
+
end
|
25
|
+
|
26
|
+
def template
|
27
|
+
TEMPLATES[next_key % 4]
|
28
|
+
end
|
29
|
+
|
30
|
+
def phrase
|
31
|
+
template.map { |type|
|
32
|
+
send(type)[next_key]
|
33
|
+
}.join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
[:adj, :adv, :article, :verb, :noun].each do |type|
|
37
|
+
define_method(type) do
|
38
|
+
instance_variable_set("@#{type}", WordType.new(type))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TripPhrase
|
2
|
+
|
3
|
+
class WordType
|
4
|
+
attr_reader :type
|
5
|
+
|
6
|
+
def initialize(type)
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def words
|
11
|
+
@words ||= words_from_file
|
12
|
+
end
|
13
|
+
|
14
|
+
def length
|
15
|
+
@length ||= words.length
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](index)
|
19
|
+
words[index % length]
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def words_from_file
|
25
|
+
words = []
|
26
|
+
IO.foreach(file_path) do |word|
|
27
|
+
word.strip!
|
28
|
+
if word =~ /^[a-z]+$/ and word.length > 1
|
29
|
+
words << word
|
30
|
+
end
|
31
|
+
end
|
32
|
+
words
|
33
|
+
end
|
34
|
+
|
35
|
+
def file_path
|
36
|
+
File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'data', "#{type}.txt")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/trip_phrase.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/trip_phrase/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Norbert Wojtowicz"]
|
6
|
+
gem.email = ["wojtowicz.norbert@gmail.com"]
|
7
|
+
gem.description = "A more memorable, fun, and useful variant of the tripcode."
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/pithyless/trip_phrase"
|
10
|
+
gem.license = "UNLICENSE"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "trip_phrase"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = TripPhrase::VERSION
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trip_phrase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Norbert Wojtowicz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A more memorable, fun, and useful variant of the tripcode.
|
15
|
+
email:
|
16
|
+
- wojtowicz.norbert@gmail.com
|
17
|
+
executables:
|
18
|
+
- trip_phrase
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- UNLICENSE
|
27
|
+
- bin/trip_phrase
|
28
|
+
- data/adj.txt
|
29
|
+
- data/adv.txt
|
30
|
+
- data/article.txt
|
31
|
+
- data/noun.txt
|
32
|
+
- data/verb.txt
|
33
|
+
- lib/trip_phrase.rb
|
34
|
+
- lib/trip_phrase/phrase_generator.rb
|
35
|
+
- lib/trip_phrase/version.rb
|
36
|
+
- lib/trip_phrase/word_type.rb
|
37
|
+
- trip_phrase.gemspec
|
38
|
+
homepage: https://github.com/pithyless/trip_phrase
|
39
|
+
licenses:
|
40
|
+
- UNLICENSE
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.19
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: A more memorable, fun, and useful variant of the tripcode.
|
63
|
+
test_files: []
|