Class: MetricDb::InMemory_Metric

Inherits:
Metric
  • Object
show all
Defined in:
lib/MetricDb/InMemory/Metric.rb

Instance Method Summary collapse

Constructor Details

#initializeInMemory_Metric

Returns a new instance of InMemory_Metric.



6
7
8
# File 'lib/MetricDb/InMemory/Metric.rb', line 6

def initialize
    @list = Array.new
end

Instance Method Details

#after(t) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/MetricDb/InMemory/Metric.rb', line 28

def after( t )
    l = Array.new
    @list.each do |r|
        l << r if r["timestamp"] > t
    end
    
    return l
end

#firstAfter(t) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/MetricDb/InMemory/Metric.rb', line 37

def firstAfter( t )
    last = nil
    @list.each do |r|
        last = r if r["timestamp"] > t
        break if r["timestamp"] <= t
    end
    
    return last
end

#getObject



15
16
17
# File 'lib/MetricDb/InMemory/Metric.rb', line 15

def get()
    return @list[0]
end

#push(value) ⇒ Object



10
11
12
13
# File 'lib/MetricDb/InMemory/Metric.rb', line 10

def push( value )
    @list.unshift Hash["value", value, "timestamp", Time.now]
    return true
end

#range(dateRange) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/MetricDb/InMemory/Metric.rb', line 19

def range( dateRange )
    l = Array.new
    @list.each do |r|
        l << r if dateRange.cover?(r["timestamp"])
    end
    
    return l
end