Class: DynoscaleRuby::Report

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

Constant Summary collapse

REPORT_TTL =

minutes

5 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publish_timestamp) ⇒ Report

Returns a new instance of Report.



10
11
12
13
# File 'lib/dynoscale_ruby/report.rb', line 10

def initialize(publish_timestamp)
   @measurements = []
   @publish_timestamp = publish_timestamp
end

Instance Attribute Details

#measurementsObject (readonly)

Returns the value of attribute measurements.



8
9
10
# File 'lib/dynoscale_ruby/report.rb', line 8

def measurements
  @measurements
end

#publish_timestampObject (readonly)

Returns the value of attribute publish_timestamp.



8
9
10
# File 'lib/dynoscale_ruby/report.rb', line 8

def publish_timestamp
  @publish_timestamp
end

Instance Method Details

#add_measurement(current_time = Time.now, metric, source, metadata) ⇒ Object



15
16
17
# File 'lib/dynoscale_ruby/report.rb', line 15

def add_measurement(current_time = Time.now, metric, source, )
   @measurements << Measurement.new(current_time.to_i, metric, source, )
end

#add_measurements(measurements) ⇒ Object



19
20
21
# File 'lib/dynoscale_ruby/report.rb', line 19

def add_measurements(measurements)
   @measurements.unshift(*measurements)
end

#expired?(current_time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dynoscale_ruby/report.rb', line 27

def expired?(current_time = Time.now)
   publish_timestamp < (current_time - REPORT_TTL)
end

#ready_to_publish?(current_time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dynoscale_ruby/report.rb', line 23

def ready_to_publish?(current_time = Time.now)
  @measurements.any? && publish_timestamp < current_time
end

#to_csvObject



31
32
33
# File 'lib/dynoscale_ruby/report.rb', line 31

def to_csv
   @measurements.reduce(""){|t, m| "#{t}#{m.timestamp},#{m.metric},#{m.source},#{m.}\n"}
end