Class: Synthra::TimeTravel::TimeContext

Inherits:
Object
  • Object
show all
Defined in:
lib/synthra/time_travel.rb

Overview

Time context for generation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_time, end_time = nil) ⇒ TimeContext

Returns a new instance of TimeContext.



315
316
317
318
319
# File 'lib/synthra/time_travel.rb', line 315

def initialize(base_time, end_time = nil)
  @base_time = base_time
  @end_time = end_time
  @range = end_time ? (base_time..end_time) : nil
end

Instance Attribute Details

#base_timeObject (readonly)

Returns the value of attribute base_time.



313
314
315
# File 'lib/synthra/time_travel.rb', line 313

def base_time
  @base_time
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



313
314
315
# File 'lib/synthra/time_travel.rb', line 313

def end_time
  @end_time
end

#rangeObject (readonly)

Returns the value of attribute range.



313
314
315
# File 'lib/synthra/time_travel.rb', line 313

def range
  @range
end

Instance Method Details

#current_timeObject



321
322
323
324
325
326
327
328
329
330
# File 'lib/synthra/time_travel.rb', line 321

def current_time
  if @range
    # Random time in range
    start_f = @base_time.to_f
    end_f = @end_time.to_f
    Time.at(start_f + rand * (end_f - start_f))
  else
    @base_time
  end
end

#range?Boolean

Returns:

  • (Boolean)


332
333
334
# File 'lib/synthra/time_travel.rb', line 332

def range?
  !@range.nil?
end