Module: Zippo::BinaryStructure::Base::InstanceMethods

Defined in:
lib/zippo/binary_structure/base.rb

Instance Method Summary collapse

Instance Method Details

#convert_to(other) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/zippo/binary_structure/base.rb', line 96

def convert_to(other)
  other.default.tap do |obj|
    self.class.common_fields_with(other).each do |field|
      obj.instance_variable_set "@#{field}", send(field)
    end
  end
end

#defaultsObject



78
79
80
81
82
83
84
# File 'lib/zippo/binary_structure/base.rb', line 78

def defaults
  self.class.structure.fields.each do |field|
    instance_variable_set "@#{field.name}", field.options[:default] if field.options[:default]
    instance_variable_set "@#{field.name}", field.options[:signature] if field.options[:signature]
  end
  self
end

#sizeObject



86
87
88
89
90
91
92
93
94
# File 'lib/zippo/binary_structure/base.rb', line 86

def size
  self.class.structure.fields.map do |field|
    if field.dependent
      send field.dependent
    else
      field.width
    end
  end.reduce(&:+)
end