Class: BinaryBlocker::ListOfEncoder

Inherits:
GroupEncoder show all
Defined in:
lib/blocker.rb

Instance Method Summary collapse

Methods inherited from GroupEncoder

attributes, attributes=, #block, clear_registered_klasses, #clone, has_bit_field, has_counted_array, has_fixed_array, has_list_of, has_one, has_one_of, include_klasses, inherited, keys, klasses, klasses=, lookup, lookup=, #method_missing, #orig_clone, register_klass, #to_h, #valid?, #value

Methods inherited from Encoder

#block, #key_value?, #me

Constructor Details

#initialize(classes, *opts) ⇒ ListOfEncoder

Returns a new instance of ListOfEncoder.



903
904
905
906
907
908
909
# File 'lib/blocker.rb', line 903

def initialize(classes, *opts)
  initialize_options(*opts)
  @count = 0
  @classes = classes
  @value = []
  initialize_data(*opts)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BinaryBlocker::GroupEncoder

Instance Method Details

#<<(val) ⇒ Object



945
946
947
# File 'lib/blocker.rb', line 945

def <<(val)
  @value << val
end

#[](offset) ⇒ Object

Raises:

  • (RangeError)


931
932
933
934
# File 'lib/blocker.rb', line 931

def [](offset)
  raise RangeError.new("Access (#{offset}) out of range (#{@value.size})") unless (0...@value.size) === offset
  @value[offset]
end

#[]=(offset, val) ⇒ Object

Raises:

  • (RangeError)


936
937
938
939
# File 'lib/blocker.rb', line 936

def []=(offset,val)
  raise RangeError.new("Access (#{offset}) out of range (#{@value.size})") unless (0...@value.size) === offset
  @value[offset] = val
end

#deblock(io) ⇒ Object



919
920
921
922
923
924
925
926
927
928
929
# File 'lib/blocker.rb', line 919

def deblock(io)
  result = []
  with_guarded_io_pos(io) do
    oe = OneOfEncoder.new(@classes, @opts)
    while oe.deblock(io)
      result << oe
      oe = OneOfEncoder.new(@classes, @opts)
    end
  end 
  @value = result
end

#eachObject



941
942
943
# File 'lib/blocker.rb', line 941

def each
  @value.each { |v| yield v }
end

#internal_block(val) ⇒ Object



915
916
917
# File 'lib/blocker.rb', line 915

def internal_block(val)
  val.inject("") { |r, o| r + o.block }
end

#sizeObject Also known as: length



949
950
951
# File 'lib/blocker.rb', line 949

def size
  @value.size
end

#value=(other) ⇒ Object



911
912
913
# File 'lib/blocker.rb', line 911

def value=(other)
  @value = other.value.clone
end