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.
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
|
Instance Method Details
#[](offset) ⇒ Object
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
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
|
#clone ⇒ Object
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
|
#size ⇒ Object
875
876
877
|
# File 'lib/blocker.rb', line 875
def size
@count
end
|
#to_h ⇒ Object
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
|
#value ⇒ Object
879
880
881
|
# File 'lib/blocker.rb', line 879
def value
self
end
|
#value=(newval) ⇒ Object
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
|