Class: Coy::RandomSource

Inherits:
Object
  • Object
show all
Defined in:
lib/coy/random_source.rb

Constant Summary collapse

DEFAULT_FILE =
"./random_source"

Class Method Summary collapse

Class Method Details

.generate(file_name = DEFAULT_FILE) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/coy/random_source.rb', line 8

def self.generate(file_name=DEFAULT_FILE)
  if block_given?
    File.open(file_name, 'w') { |fh| fh.write rand_strategy }
    yield file_name
    File.unlink(file_name)
  else
    rand_strategy
  end
end

.rand_strategyObject



18
19
20
21
22
23
24
25
# File 'lib/coy/random_source.rb', line 18

def self.rand_strategy
  some_random_bytes.inject("") do |accumulator, random_bytes|
    accumulator.tap do |acc|
      acc << random_bytes.crypt(@prev.to_s.rjust(2, random_bytes).gsub(/[^\da-zA-Z]/,'x'))
      @prev = random_bytes.hash.to_s
    end
  end
end

.some_random_bytesObject



27
28
29
# File 'lib/coy/random_source.rb', line 27

def self.some_random_bytes
  (1500..2000).map{|number| rand(number).to_s }
end