Class: BinaryBlocker::FixedArrayEncoder
Instance Method Summary
collapse
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.
837
838
839
840
841
842
843
|
# File 'lib/blocker.rb', line 837
def initialize(count, classes, *opts)
initialize_options(*opts)
@count = count
@classes = classes
@value = Array.new(count) { OneOfEncoder.new(classes, *opts) }
initialize_data(*opts)
end
|
Instance Method Details
#[](offset) ⇒ Object
888
889
890
891
|
# File 'lib/blocker.rb', line 888
def [](offset)
raise RangeError.new("Access (#{offset}) out of range (#{@count})") unless (0...@count) === offset
@value[offset]
end
|
#[]=(offset, val) ⇒ Object
893
894
895
896
|
# File 'lib/blocker.rb', line 893
def []=(offset,val)
raise RangeError.new("Access (#{offset}) out of range (#{@count})") unless (0...@count) === offset
@value[offset] = val
end
|
#clone ⇒ Object
868
869
870
|
# File 'lib/blocker.rb', line 868
def clone
result = orig_clone
end
|
#deblock(io) ⇒ Object
849
850
851
852
853
854
855
856
857
|
# File 'lib/blocker.rb', line 849
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
845
846
847
|
# File 'lib/blocker.rb', line 845
def internal_block(val)
val.inject("") { |r, o| r + o.block }
end
|
#size ⇒ Object
872
873
874
|
# File 'lib/blocker.rb', line 872
def size
@count
end
|
#to_h ⇒ Object
859
860
861
862
863
864
865
866
|
# File 'lib/blocker.rb', line 859
def to_h
result = []
@value.each do |value|
value = value.to_h if value.respond_to? :to_h
result << value
end
result
end
|
#value ⇒ Object
876
877
878
|
# File 'lib/blocker.rb', line 876
def value
self
end
|
#value=(newval) ⇒ Object
880
881
882
883
884
885
886
|
# File 'lib/blocker.rb', line 880
def value=(newval)
raise RangeError.new("Array size mismatch") unless newval.size == @count
@count.times do |i|
@value[i] = newval[i]
end
newval
end
|