Class: Rot
- Inherits:
-
Object
- Object
- Rot
- Defined in:
- lib/rot.rb
Instance Attribute Summary collapse
-
#decryption_tokenizer ⇒ Object
Returns the value of attribute decryption_tokenizer.
-
#encryption_tokenizer ⇒ Object
Returns the value of attribute encryption_tokenizer.
-
#mappings ⇒ Object
Returns the value of attribute mappings.
-
#unknown_mapping ⇒ Object
Returns the value of attribute unknown_mapping.
Instance Method Summary collapse
- #decrypt(word) ⇒ Object
- #encrypt(word) ⇒ Object
-
#initialize(mappings, unknown_mapping, encryption_tokenizer, decryption_tokenizer) ⇒ Rot
constructor
A new instance of Rot.
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_tokenizer ⇒ Object
Returns the value of attribute decryption_tokenizer.
3 4 5 |
# File 'lib/rot.rb', line 3 def decryption_tokenizer @decryption_tokenizer end |
#encryption_tokenizer ⇒ Object
Returns the value of attribute encryption_tokenizer.
3 4 5 |
# File 'lib/rot.rb', line 3 def encryption_tokenizer @encryption_tokenizer end |
#mappings ⇒ Object
Returns the value of attribute mappings.
3 4 5 |
# File 'lib/rot.rb', line 3 def mappings @mappings end |
#unknown_mapping ⇒ Object
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 |