Class: Synthra::TimeTravel::TimeContext
- Inherits:
-
Object
- Object
- Synthra::TimeTravel::TimeContext
- Defined in:
- lib/synthra/time_travel.rb
Overview
Time context for generation
Instance Attribute Summary collapse
-
#base_time ⇒ Object
readonly
Returns the value of attribute base_time.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #current_time ⇒ Object
-
#initialize(base_time, end_time = nil) ⇒ TimeContext
constructor
A new instance of TimeContext.
- #range? ⇒ Boolean
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_time ⇒ Object (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_time ⇒ Object (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 |
#range ⇒ Object (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_time ⇒ Object
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
332 333 334 |
# File 'lib/synthra/time_travel.rb', line 332 def range? !@range.nil? end |