Class: PRRD::Graph::Definition

Inherits:
Entity
  • Object
show all
Defined in:
lib/prrd/graph/definition.rb

Overview

PRRD Graph Definition class

Instance Attribute Summary

Attributes inherited from Entity

#data, #keys

Instance Method Summary collapse

Methods inherited from Entity

#method_missing, #validate_presence

Constructor Details

#initialize(values = nil) ⇒ Definition

Constructor



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/prrd/graph/definition.rb', line 11

def initialize(values = nil)
  @keys = [
    :vname,
    :rrdfile,
    :ds_name,
    :cf,
    :step,
    :start,
    :end
  ]

  super values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PRRD::Entity

Instance Method Details

#to_sObject

Transform to a DEF formatted string



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/prrd/graph/definition.rb', line 26

def to_s
  fail 'Empty definition object' if @data.empty?

  chunks = []

  @keys.each do |k|
    next unless @data.key?(k)
    case k
    when :vname
      chunks << "DEF:%s=%s" % [@data[k], @data[:rrdfile]]
    when :rrdfile
      # nope
    else
      chunks << @data[k]
    end
  end

  chunks.join ':'
end