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

register, #to_json

Constructor Details

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

Returns a new instance of Metric.



33
34
35
36
37
# File 'lib/console/event/metric.rb', line 33

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.[](**parameters) ⇒ Object



29
30
31
# File 'lib/console/event/metric.rb', line 29

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

Instance Method Details

#format(output, terminal, verbose) ⇒ Object



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

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

#to_hObject



43
44
45
# File 'lib/console/event/metric.rb', line 43

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

#value_stringObject



47
48
49
# File 'lib/console/event/metric.rb', line 47

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