Class: Profit::Metric
- Inherits:
-
Object
- Object
- Profit::Metric
- Defined in:
- lib/profit/metric.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#metric_key ⇒ Object
Returns the value of attribute metric_key.
-
#recorded_time ⇒ Object
Returns the value of attribute recorded_time.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#stop_line ⇒ Object
Returns the value of attribute stop_line.
Instance Method Summary collapse
- #display_start_time ⇒ Object
-
#initialize(metric) ⇒ Metric
constructor
A new instance of Metric.
- #point ⇒ Object
- #to_json ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/profit/metric.rb', line 5 def data @data end |
#metric_key ⇒ Object
Returns the value of attribute metric_key.
5 6 7 |
# File 'lib/profit/metric.rb', line 5 def metric_key @metric_key end |
#recorded_time ⇒ Object
Returns the value of attribute recorded_time.
5 6 7 |
# File 'lib/profit/metric.rb', line 5 def recorded_time @recorded_time end |
#start_line ⇒ Object
Returns the value of attribute start_line.
5 6 7 |
# File 'lib/profit/metric.rb', line 5 def start_line @start_line end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/profit/metric.rb', line 5 def start_time @start_time end |
#stop_line ⇒ Object
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_time ⇒ Object
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 |
#point ⇒ Object
33 34 35 |
# File 'lib/profit/metric.rb', line 33 def point { recorded_time: recorded_time, start_time: start_time } end |
#to_json ⇒ Object
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 |