Class: Graphite::Graph
- Inherits:
-
Object
- Object
- Graphite::Graph
- Defined in:
- lib/graphite/graph.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#targets ⇒ Object
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #method_missing(sym) ⇒ Object
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
4 5 6 7 |
# File 'lib/graphite/graph.rb', line 4 def initialize @targets = [] @params = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/graphite/graph.rb', line 8 def method_missing(sym) if @params.has_key?(sym.to_s) @params[sym.to_s] else super end end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/graphite/graph.rb', line 3 def params @params end |
#targets ⇒ Object
Returns the value of attribute targets.
3 4 5 |
# File 'lib/graphite/graph.rb', line 3 def targets @targets end |
Class Method Details
.from_url(url) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphite/graph.rb', line 15 def self.from_url(url) graph = self.new uri = URI(url) url_params = CGI.parse(uri.query) target_parser = Graphite::TargetParser.new url_params.delete("target").each do |t| target_parser.parse!(t) graph.targets << target_parser.tree.to_model end url_params.keys.inject(graph.params) { |acc,key| acc[key] = if url_params[key].present? && url_params[key].size==1 url_params[key].first else url_params[key] end acc } graph end |