Class: Console::Event::Metric

Inherits:
Generic
  • Object
show all
Defined in:
lib/console/event/metric.rb

Direct Known Subclasses

Exit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#as_json, register

Constructor Details

#initialize(name, value, **tags) ⇒ Metric

Returns a new instance of Metric.



31
32
33
34
35
# File 'lib/console/event/metric.rb', line 31

def initialize(name, value, **tags)
	@name = name
	@value = value
	@tags = tags
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



39
40
41
# File 'lib/console/event/metric.rb', line 39

def tags
  @tags
end

#valueObject (readonly)

Returns the value of attribute value.



38
39
40
# File 'lib/console/event/metric.rb', line 38

def value
  @value
end

Class Method Details

.[](**parameters) ⇒ Object



27
28
29
# File 'lib/console/event/metric.rb', line 27

def self.[](**parameters)
	parameters.map(&self.method(:new))
end

Instance Method Details

#format(output, terminal, verbose) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/console/event/metric.rb', line 49

def format(output, terminal, verbose)
	if @tags&.any?
		output.puts "#{value_string} #{@tags.inspect}"
	else
		output.puts value_string
	end
end

#to_hObject



41
42
43
# File 'lib/console/event/metric.rb', line 41

def to_h
	{name: @name, value: @value, tags: @tags}
end

#value_stringObject



45
46
47
# File 'lib/console/event/metric.rb', line 45

def value_string
	"#{@name}: #{@value}"
end