Class: Rot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappings, unknown_mapping, encryption_tokenizer, decryption_tokenizer) ⇒ Rot

Returns a new instance of Rot.



5
6
7
8
9
10
# File 'lib/rot.rb', line 5

def initialize mappings, unknown_mapping, encryption_tokenizer, decryption_tokenizer
  @mappings                   = mappings
  @unknown_mapping            = unknown_mapping
  @encryption_tokenizer       = encryption_tokenizer
  @decryption_tokenizer       = decryption_tokenizer
end

Instance Attribute Details

#decryption_tokenizerObject

Returns the value of attribute decryption_tokenizer.



3
4
5
# File 'lib/rot.rb', line 3

def decryption_tokenizer
  @decryption_tokenizer
end

#encryption_tokenizerObject

Returns the value of attribute encryption_tokenizer.



3
4
5
# File 'lib/rot.rb', line 3

def encryption_tokenizer
  @encryption_tokenizer
end

#mappingsObject

Returns the value of attribute mappings.



3
4
5
# File 'lib/rot.rb', line 3

def mappings
  @mappings
end

#unknown_mappingObject

Returns the value of attribute unknown_mapping.



3
4
5
# File 'lib/rot.rb', line 3

def unknown_mapping
  @unknown_mapping
end

Instance Method Details

#decrypt(word) ⇒ Object



12
13
14
# File 'lib/rot.rb', line 12

def decrypt word
  word.scan(@decryption_tokenizer).map { |char| @mappings[char] || @unknown_mapping } * ''
end

#encrypt(word) ⇒ Object



16
17
18
# File 'lib/rot.rb', line 16

def encrypt word
  word.scan(@encryption_tokenizer).map { |char| @mappings.invert[char] || @unknown_mapping } * ''
end