Class: Win32::CaptureIE::FFI::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/win32/capture_ie/ffi/struct.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, opts = nil) ⇒ Field

Returns a new instance of Field.



153
154
155
156
157
158
159
160
# File 'lib/win32/capture_ie/ffi/struct.rb', line 153

def initialize(type, name, opts=nil)
  @type = type
  @name = name
  @var = "@#{name}".to_sym
  @opts = opts || {}
  @offset = @opts[:offset] || nil
  @count = @opts[:dim] || 1
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



151
152
153
# File 'lib/win32/capture_ie/ffi/struct.rb', line 151

def count
  @count
end

#nameObject (readonly)

Returns the value of attribute name.



151
152
153
# File 'lib/win32/capture_ie/ffi/struct.rb', line 151

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



152
153
154
# File 'lib/win32/capture_ie/ffi/struct.rb', line 152

def offset
  @offset
end

#typeObject (readonly)

Returns the value of attribute type.



151
152
153
# File 'lib/win32/capture_ie/ffi/struct.rb', line 151

def type
  @type
end

#varObject (readonly)

Returns the value of attribute var.



151
152
153
# File 'lib/win32/capture_ie/ffi/struct.rb', line 151

def var
  @var
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/win32/capture_ie/ffi/struct.rb', line 162

def array?
  count > 0
end

#initObject



166
167
168
169
170
171
172
# File 'lib/win32/capture_ie/ffi/struct.rb', line 166

def init
  if array?
    init_one
  else
    (0...count).map{ init_one }
  end
end

#pack(value) ⇒ Object



178
179
180
181
182
183
184
185
186
# File 'lib/win32/capture_ie/ffi/struct.rb', line 178

def pack(value)
  if count == 1
    @type.pack(value)
  else
    raise "hoge" unless Array === value
    raise "foo" unless value.length == count
    value.map{|e| @type.pack(e) }.join
  end
end

#sizeObject



174
175
176
# File 'lib/win32/capture_ie/ffi/struct.rb', line 174

def size
  @type.size * count
end