Class: Logpos::TripleArray
- Inherits:
-
Object
- Object
- Logpos::TripleArray
- Defined in:
- lib/logpos.rb
Defined Under Namespace
Classes: TP
Instance Method Summary collapse
- #include?(time) ⇒ Boolean
-
#initialize(lastest_visited_at) ⇒ TripleArray
constructor
A new instance of TripleArray.
- #oldest ⇒ Object
- #push(time, pos) ⇒ Object
Constructor Details
#initialize(lastest_visited_at) ⇒ 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
82 83 84 |
# File 'lib/logpos.rb', line 82 def include? time !!@array.detect {|tp| tp.time == time } end |
#oldest ⇒ Object
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 |