Class: Profit::Metric

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric) ⇒ Metric

Returns a new instance of Metric.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/profit/metric.rb', line 12

def initialize(metric)
  @data = HashWithIndifferentAccess.new(metric.is_a?(String) ? JSON.parse(metric) : metric)
  @metric_key,
  @recorded_time,
  @start_line,
  @start_time,
  @stop_line = data.values_at(:metric_key,
                              :recorded_time,
                              :start_line,
                              :start_time,
                              :stop_line)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/profit/metric.rb', line 5

def data
  @data
end

#metric_keyObject

Returns the value of attribute metric_key.



5
6
7
# File 'lib/profit/metric.rb', line 5

def metric_key
  @metric_key
end

#recorded_timeObject

Returns the value of attribute recorded_time.



5
6
7
# File 'lib/profit/metric.rb', line 5

def recorded_time
  @recorded_time
end

#start_lineObject

Returns the value of attribute start_line.



5
6
7
# File 'lib/profit/metric.rb', line 5

def start_line
  @start_line
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/profit/metric.rb', line 5

def start_time
  @start_time
end

#stop_lineObject

Returns the value of attribute stop_line.



5
6
7
# File 'lib/profit/metric.rb', line 5

def stop_line
  @stop_line
end

Instance Method Details

#display_start_timeObject



37
38
39
# File 'lib/profit/metric.rb', line 37

def display_start_time
  DateTime.strptime(start_time.to_s,'%s').strftime("%H:%M:%S")
end

#pointObject



33
34
35
# File 'lib/profit/metric.rb', line 33

def point
  { recorded_time: recorded_time, start_time: start_time }
end

#to_jsonObject



25
26
27
28
29
30
31
# File 'lib/profit/metric.rb', line 25

def to_json
  { metric_key: metric_key,
    recorded_time: recorded_time,
    start_line: start_line,
    start_time: start_time.to_i,
    stop_line: stop_line }.to_json
end