Class: Zippo::BinaryStructure::Structure

Inherits:
Object
  • Object
show all
Defined in:
lib/zippo/binary_structure/structure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_class, &block) ⇒ Structure

Returns a new instance of Structure.



8
9
10
11
12
# File 'lib/zippo/binary_structure/structure.rb', line 8

def initialize(owner_class, &block)
  @fields = []
  @owner_class = owner_class
  instance_eval &block
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



21
22
23
# File 'lib/zippo/binary_structure/structure.rb', line 21

def fields
  @fields
end

#owner_classObject (readonly)

Returns the value of attribute owner_class.



21
22
23
# File 'lib/zippo/binary_structure/structure.rb', line 21

def owner_class
  @owner_class
end

Class Method Details

.create(owner_class, &block) ⇒ Object



4
5
6
7
# File 'lib/zippo/binary_structure/structure.rb', line 4

def self.create(owner_class, &block)
  structure = new(owner_class, &block)
  structure
end

Instance Method Details

#dependent?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/zippo/binary_structure/structure.rb', line 16

def dependent? field_name
  fields.detect do |field|
    field.options[:size] == field_name
  end
end

#field(name, pack, options = {}) ⇒ Object



13
14
15
# File 'lib/zippo/binary_structure/structure.rb', line 13

def field name, pack, options = {}
  @fields << StructureMember.new(name, pack, options)
end