Class: TotenDev::Metric

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Metric

Returns a new instance of Metric.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tdev_metrics/metric.rb', line 16

def initialize( hash = nil )
  if hash.nil?
    @timestamp = Time.now.getutc.to_i
  else
    @id         = hash['id'].to_i
    @name       = hash['metric']
    @project_id = hash['project'].to_i
    @place      = hash['place']
    @type       = hash['type']
    @info       = hash['info']
    @timestamp  = hash['timestamp'].to_i
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/tdev_metrics/metric.rb', line 8

def id
  @id
end

#infoObject

Returns the value of attribute info.



13
14
15
# File 'lib/tdev_metrics/metric.rb', line 13

def info
  @info
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/tdev_metrics/metric.rb', line 9

def name
  @name
end

#placeObject

Returns the value of attribute place.



11
12
13
# File 'lib/tdev_metrics/metric.rb', line 11

def place
  @place
end

#project_idObject

Returns the value of attribute project_id.



10
11
12
# File 'lib/tdev_metrics/metric.rb', line 10

def project_id
  @project_id
end

#timestampObject

Returns the value of attribute timestamp.



14
15
16
# File 'lib/tdev_metrics/metric.rb', line 14

def timestamp
  @timestamp
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/tdev_metrics/metric.rb', line 12

def type
  @type
end

Instance Method Details

#to_hashObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/tdev_metrics/metric.rb', line 30

def to_hash
  {
    'metric'    => @name,
    'project'   => @project_id,
    'place'     => @place,
    'type'      => @type,
    'info'      => @info,
    'timestamp' => @timestamp
  }
end