Class: BinaryBlocker::FixedArrayEncoder

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

Instance Method Summary collapse

Methods inherited from GroupEncoder

attributes, attributes=, #block, clear_registered_klasses, 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, #valid?

Methods inherited from Encoder

#block, #key_value?, #me

Constructor Details

#initialize(count, classes, *opts) ⇒ FixedArrayEncoder

Returns a new instance of FixedArrayEncoder.



840
841
842
843
844
845
846
# File 'lib/blocker.rb', line 840

def initialize(count, classes, *opts)
  initialize_options(*opts)
  @count = count
  @classes = classes
  @value = Array.new(count) { OneOfEncoder.new(classes, *opts) }
  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

#[](offset) ⇒ Object

Raises:

  • (RangeError)


891
892
893
894
# File 'lib/blocker.rb', line 891

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

#[]=(offset, val) ⇒ Object

Raises:

  • (RangeError)


896
897
898
899
# File 'lib/blocker.rb', line 896

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

#cloneObject



871
872
873
# File 'lib/blocker.rb', line 871

def clone
  result = orig_clone
end

#deblock(io) ⇒ Object



852
853
854
855
856
857
858
859
860
# File 'lib/blocker.rb', line 852

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

#internal_block(val) ⇒ Object



848
849
850
# File 'lib/blocker.rb', line 848

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

#sizeObject



875
876
877
# File 'lib/blocker.rb', line 875

def size
	@count
end

#to_hObject



862
863
864
865
866
867
868
869
# File 'lib/blocker.rb', line 862

def to_h
  result = []
			@value.each do |value|
    value = value.to_h if value.respond_to? :to_h
result << value
  end    
  result
end

#valueObject



879
880
881
# File 'lib/blocker.rb', line 879

def value
	self
end

#value=(newval) ⇒ Object

Raises:

  • (RangeError)


883
884
885
886
887
888
889
# File 'lib/blocker.rb', line 883

def value=(newval)
	raise RangeError.new("Array size mismatch") unless newval.size == @count
    @count.times do |i|			
		@value[i] = newval[i]
	end
	newval
end