Class: TimeStep::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/timesteps/timestep_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(timestep, format: nil) ⇒ Query

Returns a new instance of Query.



5
6
7
8
# File 'lib/timesteps/timestep_query.rb', line 5

def initialize (timestep, format: nil)
  @timestep = timestep
  @format   = format
end

Instance Method Details

#just_after_time_of(time) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/timesteps/timestep_query.rb', line 30

def just_after_time_of (time)
  idx = @timestep.index_at(time)
  if idx.denominator == 1
    time0 = time
  else
    time0 = @timestep.time_at(idx.ceil)
  end
  return __format__(time0)
end

#just_before_time_of(time) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/timesteps/timestep_query.rb', line 20

def just_before_time_of (time)
  idx = @timestep.index_at(time)
  if idx.denominator == 1
    time0 = time
  else
    time0 = @timestep.time_at(idx.floor)
  end
  return __format__(time0)
end

#just_time?(time) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/timesteps/timestep_query.rb', line 16

def just_time? (time)
  return @timestep.index_at(time).denominator == 1
end

#next_time_of(time) ⇒ Object



44
45
46
# File 'lib/timesteps/timestep_query.rb', line 44

def next_time_of (time)
  return __format__(@timestep.next_time_of(time))
end

#prev_time_of(time) ⇒ Object



40
41
42
# File 'lib/timesteps/timestep_query.rb', line 40

def prev_time_of (time)
  return __format__(@timestep.prev_time_of(time))
end