Class: Slate::Graph
- Inherits:
-
Object
- Object
- Slate::Graph
- Defined in:
- lib/slate/graph.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#until ⇒ Object
Returns the value of attribute until.
Instance Method Summary collapse
- #<<(target) ⇒ Object
- #download(format = :png) ⇒ Object
-
#initialize(client, options = {}) ⇒ Graph
constructor
Public: Creates a new graph instance.
-
#url(format = :png) ⇒ Object
Public: Generate a URL to the image of the graph.
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, ={}) @client = client @from = [:from] @until = [:until] end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/slate/graph.rb', line 6 def from @from end |
#until ⇒ Object
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) = .push(["format", format.to_s]) "#{@client.endpoint}/render?#{params()}" end |