Class: BinData::SanitizedPrototype

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

Instance Method Summary collapse

Constructor Details

#initialize(obj_type, obj_params, hints) ⇒ SanitizedPrototype

Returns a new instance of SanitizedPrototype.



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

def initialize(obj_type, obj_params, hints)
  raw_hints = hints.dup
  if raw_hints[:endian].respond_to?(:endian)
    raw_hints[:endian] = raw_hints[:endian].endian
  end
  obj_params ||= {}

  if BinData::Base === obj_type
    obj_class = obj_type
  else
    obj_class = RegisteredClasses.lookup(obj_type, raw_hints)
  end

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

Instance Method Details

#has_parameter?(param) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/bindata/sanitize.rb', line 30

def has_parameter?(param)
  if defined? @factory
    @factory.has_parameter?(param)
  else
    @obj_params.has_parameter?(param)
  end
end

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



38
39
40
41
42
# File 'lib/bindata/sanitize.rb', line 38

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

  @factory.new(value, parent)
end