Class: Wonkavision::Plugins::Aggregation::Dimension
- Inherits:
-
Object
- Object
- Wonkavision::Plugins::Aggregation::Dimension
- Defined in:
- lib/wonkavision/plugins/analytics/aggregation/dimension.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
- #caption(caption_key = nil, options = {}) ⇒ Object
-
#from ⇒ Object
readonly
Returns the value of attribute from.
- #key(key = nil, options = {}) ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #sort(sort_key = nil, options = {}) ⇒ Object (also: #sort_by)
Instance Method Summary collapse
- #attribute(*attribute_list) ⇒ Object
- #extract(data) ⇒ Object
-
#initialize(name, options = {}, &block) ⇒ Dimension
constructor
A new instance of Dimension.
Constructor Details
#initialize(name, options = {}, &block) ⇒ Dimension
Returns a new instance of Dimension.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 10 def initialize(name,={},&block) @name = name @options = @attributes = HashWithIndifferentAccess.new @from = [:from] key [:key] if [:key] sort [:sort] if [:sort] [:caption] if [:caption] self.instance_eval(&block) if block key name unless key end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 7 def attributes @attributes end |
#caption(caption_key = nil, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 39 def (=nil, ={}) return @caption || @key unless attribute(, ) unless attributes[] @caption = end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
7 8 9 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 7 def from @from end |
#key(key = nil, options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 45 def key(key=nil, ={}) return @key unless key attribute(key, ) unless attributes[key] @key = key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 7 def @options end |
#sort(sort_key = nil, options = {}) ⇒ Object Also known as: sort_by
32 33 34 35 36 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 32 def sort(sort_key = nil, ={}) return @sort || @key unless sort_key attribute(sort_key, ) unless attributes[sort_key] @sort = sort_key end |
Instance Method Details
#attribute(*attribute_list) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 22 def attribute(*attribute_list) raise "No attribute names were specified when calling '#attribute'" if attribute_list.blank? = attribute_list. || {} attribute_list.flatten.each do |attribute| @attributes[attribute] = Attribute.new(attribute,) end end |
#extract(data) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/wonkavision/plugins/analytics/aggregation/dimension.rb', line 51 def extract(data) dimension_data = data[from.to_s] if from dimension_data ||= data[name.to_s] if data[name.to_s].kind_of?(Hash) dimension_data ||= data attributes.values.inject({}) do |,attribute| .tap { |m| m[attribute.name.to_s] = attribute.extract(dimension_data)}; end end |