Module: Matrext

Defined in:
lib/matrext/core.rb,
lib/matrext.rb,
lib/matrext/version.rb

Overview

lib/matrext/core.rb The core processing unit

Defined Under Namespace

Classes: Base

Constant Summary collapse

NOISE_MIN_DEFAULT =
4
NOISE_MAX_DEFAULT =
6
DELAY_MIN_DEFAULT =
0.009
DELAY_MAX_DEFAULT =
0.012
VERSION =
'0.4.6'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#alpha_charsObject

Returns the value of attribute alpha_chars.



10
11
12
# File 'lib/matrext/core.rb', line 10

def alpha_chars
  @alpha_chars
end

#numeric_charsObject

Returns the value of attribute numeric_chars.



10
11
12
# File 'lib/matrext/core.rb', line 10

def numeric_chars
  @numeric_chars
end

#random_charsObject

Returns the value of attribute random_chars.



10
11
12
# File 'lib/matrext/core.rb', line 10

def random_chars
  @random_chars
end

Class Method Details

.process(options = {:oneline => false, :alpha => true, :numeric => true, :random => true}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/matrext/core.rb', line 12

def self.process(options = {:oneline => false, :alpha => true, :numeric => true, :random => true})
  character_pool = self.create_character_pool(options)

  letters = options[:phrase]

  unless options[:speed].nil?
    speed = options[:speed].to_sym
  end

  case speed
  when :insane
    noise_min = 1
    noise_max = 2
    delay_min = 0.0005
    delay_max = 0.0015
  when :fast
    noise_min = 2
    noise_max = 4
    delay_min = 0.003
    delay_max = 0.005
  when :slow
    noise_min = 5
    noise_max = 7
    delay_min = 0.03
    delay_max = 0.05
  else
    noise_min = NOISE_MIN_DEFAULT
    noise_max = NOISE_MIN_DEFAULT
    delay_min = DELAY_MIN_DEFAULT
    delay_max = DELAY_MAX_DEFAULT
  end

  letters.each_char do |l|
    letter_noise = rand(noise_min..noise_max)
    letter_delay = rand(delay_min..delay_max)
   
    (0..letter_noise).each do |n|
      print get_random_letter(character_pool)
      sleep(letter_delay)
      print "\b"
    end
    print l.upcase
    sleep(letter_delay)
  end

  if options[:oneline].equal? false
    puts
  end
end