Class: GraphiteMetric::Plaintext

Inherits:
Struct
  • Object
show all
Defined in:
lib/graphite-metric/plaintext.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Plaintext

Returns a new instance of Plaintext.



3
4
5
6
# File 'lib/graphite-metric/plaintext.rb', line 3

def initialize(*args)
  super
  self[:timestamp] ||= Time.now.utc.to_i
end

Instance Attribute Details

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



2
3
4
# File 'lib/graphite-metric/plaintext.rb', line 2

def key
  @key
end

#timestampObject

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



2
3
4
# File 'lib/graphite-metric/plaintext.rb', line 2

def timestamp
  @timestamp
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/graphite-metric/plaintext.rb', line 2

def value
  @value
end

Class Method Details

.from_array(array) ⇒ Object



18
19
20
21
22
# File 'lib/graphite-metric/plaintext.rb', line 18

def self.from_array(array)
  array.inject([]) do |result, hash|
    result << from_hash(hash)
  end
end

.from_hash(hash) ⇒ Object



12
13
14
15
16
# File 'lib/graphite-metric/plaintext.rb', line 12

def self.from_hash(hash)
  metric = new
  members.each { |member| metric[member] = hash[member] if hash.has_key?(member) }
  metric
end

Instance Method Details

#to_sObject



8
9
10
# File 'lib/graphite-metric/plaintext.rb', line 8

def to_s
  [key, value, timestamp].join(" ")
end