Class: Spectator::MeterId
- Inherits:
-
Object
- Object
- Spectator::MeterId
- Defined in:
- lib/spectator/meter_id.rb
Overview
Identifier for a meter or Measure
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare our id and tags against another MeterId.
-
#initialize(name, maybe_tags = nil) ⇒ MeterId
constructor
A new instance of MeterId.
-
#key ⇒ Object
lazyily compute a key to be used in hashes for efficiency.
-
#to_s ⇒ Object
A string representation for debugging purposes.
-
#with_stat(stat_value) ⇒ Object
Create a new MeterId with key=statistic and the given value.
-
#with_tag(key, value) ⇒ Object
Create a new MeterId with a given key and value.
Constructor Details
#initialize(name, maybe_tags = nil) ⇒ MeterId
Returns a new instance of MeterId.
5 6 7 8 9 10 11 12 |
# File 'lib/spectator/meter_id.rb', line 5 def initialize(name, = nil) = .nil? ? {} : @name = name.to_sym @tags = {} .each { |k, v| @tags[k.to_sym] = v.to_sym } @tags.freeze @key = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/spectator/meter_id.rb', line 4 def name @name end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
4 5 6 |
# File 'lib/spectator/meter_id.rb', line 4 def @tags end |
Instance Method Details
#==(other) ⇒ Object
Compare our id and tags against another MeterId
48 49 50 |
# File 'lib/spectator/meter_id.rb', line 48 def ==(other) other.name == @name && other. == @tags end |
#key ⇒ Object
lazyily compute a key to be used in hashes for efficiency
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spectator/meter_id.rb', line 27 def key if @key.nil? hash_key = @name.to_s @key = hash_key keys = @tags.keys keys.sort keys.each do |k| v = [k] hash_key += "|#{k}|#{v}" end @key = hash_key end @key end |
#to_s ⇒ Object
A string representation for debugging purposes
43 44 45 |
# File 'lib/spectator/meter_id.rb', line 43 def to_s "MeterId{name=#{@name}, tags=#{@tags}}" end |
#with_stat(stat_value) ⇒ Object
Create a new MeterId with key=statistic and the given value
22 23 24 |
# File 'lib/spectator/meter_id.rb', line 22 def with_stat(stat_value) with_tag(:statistic, stat_value) end |