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.2'

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

.alpha_charsObject



64
65
66
# File 'lib/matrext/core.rb', line 64

def self.alpha_chars
  ((65..90).map{|i| i.chr} | (97..122).map{|i| i.chr})
end

.create_character_pool(options) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/matrext/core.rb', line 76

def self.create_character_pool(options)
  chars = []

  chars = chars | alpha_chars if options.fetch(:alpha)
  chars = chars | numeric_chars if options.fetch(:numeric)
  chars = chars | random_chars if options.fetch(:random)
  
  return chars
end

.get_random_letter(chars) ⇒ Object



86
87
88
# File 'lib/matrext/core.rb', line 86

def self.get_random_letter(chars)
  chars[rand(0..chars.length-1)]
end

.numeric_charsObject



68
69
70
# File 'lib/matrext/core.rb', line 68

def self.numeric_chars
  (48..57).map{|i| i.chr}
end

.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

.random_charsObject



72
73
74
# File 'lib/matrext/core.rb', line 72

def self.random_chars
  ((33..47).map{|i| i.chr} | (91..96).map{|i| i.chr} | (123..126).map{|i| i.chr})
end