Class: BinData::SanitizedPrototype

Inherits:
SanitizedParameter show all
Defined in:
lib/bindata/sanitize.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj_type, obj_params, endian) ⇒ SanitizedPrototype

Returns a new instance of SanitizedPrototype.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bindata/sanitize.rb', line 9

def initialize(obj_type, obj_params, endian)
  endian = endian.endian if endian.respond_to? :endian
  obj_params ||= {}
  if BinData::Base === obj_type or obj_type.is_a?(Class)
    obj_class = obj_type
  else
    obj_class = RegisteredClasses.lookup(obj_type, endian)
  end

  if BinData::Base === obj_class
    @factory = obj_class
  else
    @obj_class  = obj_class
    @obj_params = SanitizedParameters.new(obj_params, @obj_class, endian)
  end
end

Instance Method Details

#instantiate(value = nil, parent = nil) ⇒ Object



26
27
28
29
30
# File 'lib/bindata/sanitize.rb', line 26

def instantiate(value = nil, parent = nil)
  @factory ||= @obj_class.new(@obj_params)

  @factory.new(value, parent)
end