Class: BareTypes::ArrayFixedLen
- Defined in:
- lib/types.rb,
lib/generative_testing/monkey_patch.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(otherType) ⇒ Object
- #create_input ⇒ Object
- #cycle_search(seen) ⇒ Object
- #decode(rest) ⇒ Object
- #encode(arr, buffer) ⇒ Object
- #finalize_references(schema) ⇒ Object
-
#initialize(type, size) ⇒ ArrayFixedLen
constructor
A new instance of ArrayFixedLen.
- #to_schema(buffer) ⇒ Object
Constructor Details
#initialize(type, size) ⇒ ArrayFixedLen
Returns a new instance of ArrayFixedLen.
744 745 746 747 748 749 |
# File 'lib/types.rb', line 744 def initialize(type, size) @type = type @size = size raise VoidUsedOutsideTaggedSet.new("Void type may not be used as type of fixed length array.") if type.class == BareTypes::Void raise MinimumSizeError.new("ArrayFixedLen size must be > 0") if size < 1 end |
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
722 723 724 |
# File 'lib/types.rb', line 722 def size @size end |
#type ⇒ Object
Returns the value of attribute type.
722 723 724 |
# File 'lib/types.rb', line 722 def type @type end |
Class Method Details
.make(depth, names) ⇒ Object
195 196 197 |
# File 'lib/generative_testing/monkey_patch.rb', line 195 def self.make(depth, names) self.new(get_type(depth + 1, names,), rand(ARRAY_MAX_SIZE) + 1) end |
Instance Method Details
#==(otherType) ⇒ Object
730 731 732 |
# File 'lib/types.rb', line 730 def ==(otherType) return otherType.class == BareTypes::ArrayFixedLen && otherType.type == @type && otherType.size == @size end |
#create_input ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/generative_testing/monkey_patch.rb', line 199 def create_input arr = [] 0.upto(@size - 1) do arr << @type.create_input end arr end |
#cycle_search(seen) ⇒ Object
724 725 726 727 728 |
# File 'lib/types.rb', line 724 def cycle_search(seen) seen.add(self) @type.cycle_search(seen) seen.pop end |
#decode(rest) ⇒ Object
758 759 760 761 762 763 764 765 |
# File 'lib/types.rb', line 758 def decode(rest) array = [] @size.times do arrVal, rest = @type.decode(rest) array << arrVal end return array, rest end |
#encode(arr, buffer) ⇒ Object
751 752 753 754 755 756 |
# File 'lib/types.rb', line 751 def encode(arr, buffer) raise SchemaMismatch.new("This ArrayFixedLen is of length #{@size.to_s} but you passed an array of length #{arr.size}") if arr.size != @size arr.each do |item| @type.encode(item, buffer) end end |
#finalize_references(schema) ⇒ Object
734 735 736 737 738 739 740 741 742 |
# File 'lib/types.rb', line 734 def finalize_references(schema) return if @finalized @finalized = true if @type.is_a?(Symbol) @type = Reference.new(@type, schema[@type]) else @type.finalize_references(schema) end end |
#to_schema(buffer) ⇒ Object
767 768 769 770 |
# File 'lib/types.rb', line 767 def to_schema(buffer) buffer << "[#{@size}]" @type.to_schema(buffer) end |