Module: Operation::Great::Justice
- Defined in:
- lib/operation/great/justice.rb,
lib/operation/great/justice/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .adjectives ⇒ Object
-
.generate(token) ⇒ Object
Given a token try and deterministly generate a code name, which will always be the same for any given token.
- .nouns ⇒ Object
Class Method Details
.adjectives ⇒ Object
34 35 36 |
# File 'lib/operation/great/justice.rb', line 34 def adjectives @adjectives ||= File.read(File.('../../../../adjectives.txt', __FILE__)).split("\n") end |
.generate(token) ⇒ Object
Given a token try and deterministly generate a code name, which will always be the same for any given token.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/operation/great/justice.rb', line 12 def generate(token) first = Zlib.crc32(token) last = Zlib.crc32(token.reverse) first = (first.to_f / 0xffffffff * adjectives.size).to_i last = (last.to_f / 0xffffffff * nouns.size).to_i # Collect our words first = adjectives[first] last = nouns[last] # Capitalize our words first = first.slice(0,1).capitalize + first.slice(1..-1) last = last.slice(0,1).capitalize + last.slice(1..-1) "Operation #{first} #{last}" end |
.nouns ⇒ Object
30 31 32 |
# File 'lib/operation/great/justice.rb', line 30 def nouns @nouns ||= File.read(File.('../../../../nouns.txt', __FILE__)).split("\n") end |