Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/archipelago/oneline.rb
Overview
Adds a few methods to String, some using the inline gem.
Constant Summary collapse
- E =
[0.1, 0.01]
- Q =
[6, 3]
- THRESHOLDS =
[1024]
Instance Method Summary collapse
- #decode_level ⇒ Object
- #decode_status ⇒ Object
- #oneline_decode(chunk) ⇒ Object
- #oneline_done ⇒ Object
- #oneline_encode(chunk_size) ⇒ Object
Instance Method Details
#decode_level ⇒ Object
591 592 593 594 595 596 597 |
# File 'lib/archipelago/oneline.rb', line 591 def decode_level ones = 0 decode_status[0..(size + @_aux_blocks.size)].split(//).each do |s| ones += 1 if s == "1" end ones.to_f / (size + @_aux_blocks.size).to_f end |
#decode_status ⇒ Object
586 587 588 589 |
# File 'lib/archipelago/oneline.rb', line 586 def decode_status return nil unless @_decode_status @_decode_status.unpack("b*").first end |
#oneline_decode(chunk) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/archipelago/oneline.rb', line 558 def oneline_decode(chunk) needed_size = chunk[4..7].unpack("L").first if size == 0 concat("\000" * needed_size) elsif size != needed_size raise "The argument to oneline_decode must be a chunk produced by oneline_encode from the same source" end @_decode_status ||= "\000" * (((needed_size + get_aux_blocks) / 8) + 1) @_known_chunks ||= [] @_aux_blocks ||= "\000" * get_aux_blocks found_new_block = _decode_chunk(chunk, @_decode_status, @_aux_blocks) do_decode if found_new_block @_known_chunks.unshift(chunk) nil while do_decode return oneline_done end |
#oneline_done ⇒ Object
581 582 583 584 |
# File 'lib/archipelago/oneline.rb', line 581 def oneline_done return nil unless @_decode_status return _oneline_done(@_decode_status) end |
#oneline_encode(chunk_size) ⇒ Object
553 554 555 556 |
# File 'lib/archipelago/oneline.rb', line 553 def oneline_encode(chunk_size) ensure_aux_blocks return _get_chunk(chunk_size, @_aux_blocks) end |