Class: Graphene::OverX
- Inherits:
-
Object
- Object
- Graphene::OverX
- Includes:
- TwoDGraphs, LazyEnumerable
- Defined in:
- lib/graphene/over_x.rb
Overview
Groups the stats of resources by the given method symbol or lambda.
Example by date
Graphene.percentages(logs, :browser).over(:date)
=> {#<Date: 2012-07-22> => [["Firefox", 45], ["Chrome", 40], ["Internet Explorer", 15]],
#<Date: 2012-07-23> => [["Firefox", 41], ["Chrome", 40], ["Internet Explorer", 19]],
#<Date: 2012-07-24> => [["Chrome", 50], ["Firefox", 40], ["Internet Explorer", 10]]}
See LazyEnumerable, Graphene::Tablize and Graphene::TwoDGraphs for more documentation.
If your X objects can be put into a range, Graphene will attempt to fill in any gaps along the X axis. But if they can’t be ranged (e.g. formatted strings), you have several options to fill them in yourself:
Graphene.percentages(logs, :browser).over(->(l) { l.date.strftime('%B %Y') }, [an array of all month/year in the logs])
Graphene.percentages(logs, :browser).over(->(l) { l.date.strftime('%B %Y') }) { |str| somehow parse the month/year and return the next one }
Instance Attribute Summary collapse
-
#result_set ⇒ Object
readonly
The attribute that are being statted, passed in the constructor.
Instance Method Summary collapse
-
#initialize(result_set, attr_or_lambda, filler = nil, &filler_block) ⇒ OverX
constructor
Accepts a ResultSet object (i.e. Graphene::Subtotals or Graphene::Percentages), and a method symbol or proc/lambda to build the X axis.
-
#to_hash ⇒ Object
Returns a Hash representation of the results.
-
#to_s ⇒ Object
Returns a string representation of the results.
Methods included from TwoDGraphs
#accumulator_bar_graph, #dot_graph, #line_graph, #net_graph
Methods included from LazyEnumerable
Constructor Details
#initialize(result_set, attr_or_lambda, filler = nil, &filler_block) ⇒ OverX
Accepts a ResultSet object (i.e. Graphene::Subtotals or Graphene::Percentages), and a method symbol or proc/lambda to build the X axis
28 29 30 31 32 33 |
# File 'lib/graphene/over_x.rb', line 28 def initialize(result_set, attr_or_lambda, filler=nil, &filler_block) @result_set = result_set @attribute = attr_or_lambda @filler = filler_block || filler @results = {} end |
Instance Attribute Details
#result_set ⇒ Object (readonly)
The attribute that are being statted, passed in the constructor
24 25 26 |
# File 'lib/graphene/over_x.rb', line 24 def result_set @result_set end |
Instance Method Details
#to_hash ⇒ Object
Returns a Hash representation of the results
41 42 43 |
# File 'lib/graphene/over_x.rb', line 41 def to_hash @results.clone end |
#to_s ⇒ Object
Returns a string representation of the results
36 37 38 |
# File 'lib/graphene/over_x.rb', line 36 def to_s to_hash.to_s end |