Class: Caper::TimeVal

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TimeVal

Returns a new instance of TimeVal.



10
11
12
13
14
15
16
# File 'lib/caper/time_val.rb', line 10

def initialize(*args)
  if args.size == 1 and (t=args[0]).kind_of?(Time)
    self.time = t
  else
    super(*args)
  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.



25
26
27
# File 'lib/caper/time_val.rb', line 25

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

#time=(t) ⇒ Time

Sets the time value from a ruby Time object

Parameters:

  • t (Time)

    A ruby time object from which to set the time.

Returns:

  • (Time)

    Returns the same Time object supplied per convention.



39
40
41
42
43
# File 'lib/caper/time_val.rb', line 39

def time=(t)
  self.tv_sec = t.tv_sec
  self.tv_usec = t.tv_usec
  return t
end