Class: Huff::Decoder
- Inherits:
-
Object
- Object
- Huff::Decoder
- Defined in:
- lib/huff/decoder.rb
Instance Method Summary collapse
- #decode_36(text) ⇒ Object
- #decode_string(text) ⇒ Object
-
#initialize(encoding_tree) ⇒ Decoder
constructor
A new instance of Decoder.
Constructor Details
#initialize(encoding_tree) ⇒ Decoder
Returns a new instance of Decoder.
3 4 5 |
# File 'lib/huff/decoder.rb', line 3 def initialize(encoding_tree) @encoding_tree = encoding_tree end |
Instance Method Details
#decode_36(text) ⇒ Object
17 18 19 |
# File 'lib/huff/decoder.rb', line 17 def decode_36(text) decode_string(text.to_i(36).to_s(2)) end |
#decode_string(text) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/huff/decoder.rb', line 7 def decode_string(text) text_array = text.each_char.to_a result = '' until text_array.empty? letter, text_array = decode(@encoding_tree, text_array) result << letter end result end |