Class: Carbonator::Parser
- Inherits:
-
Object
- Object
- Carbonator::Parser
- Defined in:
- lib/carbonator/parser.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Parser
constructor
A new instance of Parser.
- #measurement?(data) ⇒ Boolean
- #metric(data) ⇒ Object
- #parse(data) ⇒ Object
- #timestamp(data) ⇒ Object
- #value(data) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Parser
Returns a new instance of Parser.
5 6 7 |
# File 'lib/carbonator/parser.rb', line 5 def initialize(opts={}) self.prefix = opts[:prefix] || 'carbonator' end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/carbonator/parser.rb', line 3 def prefix @prefix end |
Instance Method Details
#measurement?(data) ⇒ Boolean
25 26 27 |
# File 'lib/carbonator/parser.rb', line 25 def measurement?(data) data.has_key?('measure') && data.has_key?('value') end |
#metric(data) ⇒ Object
9 10 11 |
# File 'lib/carbonator/parser.rb', line 9 def metric(data) prefix ? "#{prefix}.#{data['measure']}" : data['measure'] end |
#parse(data) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/carbonator/parser.rb', line 13 def parse(data) return nil unless measurement?(data) metric = metric(data) value = value(data) = (data) "#{metric} #{value} #{timestamp}" end |
#timestamp(data) ⇒ Object
21 22 23 |
# File 'lib/carbonator/parser.rb', line 21 def (data) data['timestamp'] || Time.now.to_i end |
#value(data) ⇒ Object
29 30 31 |
# File 'lib/carbonator/parser.rb', line 29 def value(data) data['value'] end |