Class: Slate::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/slate/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Graph

Public: Creates a new graph instance.

client - A configured Slate::Client instance. options - Options for creating the graph (default: {}):

:from  - The String to start the data in the graph (optional).
:until - The String to end the data in the graph (optional).

Examples

Slate::Graph.new(client)

Slate::Graph.new(client, { from: "-1d" })

Slate::Graph.new(client, { until: "-1h" })


22
23
24
25
26
# File 'lib/slate/graph.rb', line 22

def initialize(client, options={})
  @client  = client
  @from    = options[:from]
  @until   = options[:until]
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/slate/graph.rb', line 6

def from
  @from
end

#untilObject

Returns the value of attribute until.



6
7
8
# File 'lib/slate/graph.rb', line 6

def until
  @until
end

Instance Method Details

#<<(target) ⇒ Object



28
29
30
# File 'lib/slate/graph.rb', line 28

def <<(target)
  @target = target
end

#download(format = :png) ⇒ Object



50
51
52
# File 'lib/slate/graph.rb', line 50

def download(format=:png)
  RestClient.get url(format)
end

#url(format = :png) ⇒ Object

Public: Generate a URL to the image of the graph.

format - The format of the graph to return, as a Symbol (default: :png).

Examples

url
# => "http://example.com/render?format=png"

url(:svg)
# => "http://example.com/render?format=svg"

Returns the URL String.



45
46
47
48
# File 'lib/slate/graph.rb', line 45

def url(format=:png)
  options = url_options.push(["format", format.to_s])
  "#{@client.endpoint}/render?#{params(options)}"
end