Class: FFI::PCap::TimeVal

Inherits:
Struct
  • Object
show all
Includes:
DRY::StructHelper
Defined in:
lib/ffi/pcap/time_val.rb

Instance Method Summary collapse

Constructor Details

#initialize(timeval = nil) ⇒ TimeVal

Initializes the new FFI::PCap::TimeVal.

Parameters:

  • timeval (Time, FFI::Pointer) (defaults to: nil)

    A Time object or a pointer to another FFI::PCap::TimeVal.



18
19
20
21
22
23
24
25
26
27
# File 'lib/ffi/pcap/time_val.rb', line 18

def initialize(timeval=nil)
  case timeval
  when Time
    super()

    self.time = timeval
  when Pointer then super(timeval)
  else              super()
  end
end

Instance Method Details

#timeTime Also known as: to_time

Returns the time value as a ruby Time object.

Returns:

  • (Time)

    A ruby time object derived from this TimeVal.



38
39
40
# File 'lib/ffi/pcap/time_val.rb', line 38

def time
  Time.at(self.tv_sec, self.tv_usec)
end

#time=(new_time) ⇒ Time

Sets the time value from a ruby Time object

Parameters:

  • new_time (Time)

    A ruby time object from which to set the time.

Returns:

  • (Time)

    Returns the same Time object supplied per convention.



53
54
55
56
57
58
# File 'lib/ffi/pcap/time_val.rb', line 53

def time=(new_time)
  self.tv_sec  = new_time.tv_sec
  self.tv_usec = new_time.tv_usec

  return new_time
end