Class: Logpos::TripleArray

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

Defined Under Namespace

Classes: TP

Instance Method Summary collapse

Constructor Details

#initialize(lastest_visited_at) ⇒ TripleArray

Returns a new instance of TripleArray.



69
70
71
72
# File 'lib/logpos.rb', line 69

def initialize lastest_visited_at
  @lastest_visited_at = lastest_visited_at
  @array = Array.new(3, TP.new(0, Time.at(0)))
end

Instance Method Details

#include?(time) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/logpos.rb', line 82

def include? time
  !!@array.detect {|tp| tp.time == time }
end

#oldestObject



86
87
88
# File 'lib/logpos.rb', line 86

def oldest
  @array.select {|a| a.time <= @lastest_visited_at }.sort {|a, b| a.time <=> b.time}[-1]
end

#push(time, pos) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/logpos.rb', line 74

def push time, pos
  return nil if include? time

  @array[0..1] = @array[1..2]
  @array[2] = TP.new(time,  pos)
  @array
end