class FortuneTeller::MomentStruct

We use MomentStruct for objects with scheduled changes

Attributes

future[R]
start[R]

Public Class Methods

new(**args) click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 6
def initialize(**args)
  @start = FortuneTeller::MomentStructBase.new args
  @future = []
end

Public Instance Methods

on(date) click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 38
def on(date)
  FortuneTeller::MomentStructMoment.new(self, date)
end
read(date) click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 15
def read(date)
  return @start if @future[0][:date] > date
  future_ct = @future.length
  @future.each_with_index do |f, i|
    if (i == (future_ct - 1)) || (@future[(i + 1)][:date] > date)
      return f[:struct]
    end
  end
end
read_for_writing(date) click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 25
def read_for_writing(date)
  i = 0
  while i < @future.length
    future = @future[i]
    return future[:struct] if future[:date] == date
    break if future[:date] > date
    i += 1
  end
  current = (i.zero? ? @start : @future[(i - 1)][:struct])
  @future.insert(i, date: date, struct: current.clone)
  @future[i][:struct]
end
to_reader() click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 11
def to_reader
  FortuneTeller::MomentStructReader.new(self)
end

Private Instance Methods

insert_at(index, date) click to toggle source
# File lib/fortuneteller/moment_struct.rb, line 44
def insert_at(index, date); end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/fortuneteller/moment_struct.rb, line 46
def method_missing(name, *args)
  if name.to_s.end_with?('=') || @start.respond_to?(name)
    @start.send(name, *args)
  else
    super
  end
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/fortuneteller/moment_struct.rb, line 54
def respond_to_missing?(name, include_private = false)
  @start.respond_to?(name) || super
end