Class: PRRD::Graph::Vrule

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

Overview

PRRD Graph Vrule 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) ⇒ Vrule

Constructor



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

def initialize(values = nil)
  @keys = [
    :time,
    :color,
    :legend,
    :dashes,
    :dashes_offset
  ]

  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 VRULE formatted string



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/prrd/graph/vrule.rb', line 24

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

  validate_presence :time, :color

  chunks = []

  @keys.each do |k|
    next unless @data.key?(k)
    case k
    when :time
      chunks << "VRULE:%s%s" % [@data[k], @data[:color]]
    when :color
      # nope
    when :dashes
      chunks << "dashes=\"%s\"" % @data[k]
    when :dashes_offset
      chunks << "dashes-offset=\"%s\"" % @data[k]
    else
      chunks << @data[k]
    end
  end

  chunks.join ':'
end