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.



23
24
25
# File 'lib/zippo/binary_structure/structure.rb', line 23

def fields
  @fields
end

#owner_classObject (readonly)

Returns the value of attribute owner_class.



23
24
25
# File 'lib/zippo/binary_structure/structure.rb', line 23

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)


18
19
20
21
22
# File 'lib/zippo/binary_structure/structure.rb', line 18

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

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



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

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