Class: Dakwak::Analytics::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/dakwak/analytics/sheet.rb

Overview

An analytics sheet is a container of stats that can be submitted to the analytics platform, dakana.

The usage is very simple. [] and []= operators are overloaded to allow you to access sheets just like you would a Hash. When your done collecting stats (the work is over), submit it using #commit!

Here’s an example:

class FlowerHunter
  def initialize
    # Prepare the sheet here
    @sheet = Sheet.new({
      :zombie_threat_eradicated => false,
      :flowers  => {
        :watered => 0,
        :plucked => 0
      }
    })
    super()
  end

   def tend_to_flowers()
     # water a flower
     @sheet[:flowers][:watered] += 1
     # pluck 5 for your special someone
     @sheet[:flowers][:plucked] = 5
   end

   def kill_zombies()
     # ...
     # BFG picked up
     @sheet[:zombie_threat_eradicated] = true
     # our work is done, let's submit the stats
     @sheet.commit!
   end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = {}) ⇒ Sheet

Convenience constructor for building a sheet with initial stats



49
50
51
# File 'lib/dakwak/analytics/sheet.rb', line 49

def initialize(content = {})
  @content = content
end

Instance Attribute Details

#contentObject

:nodoc:



46
47
48
# File 'lib/dakwak/analytics/sheet.rb', line 46

def content
  @content
end

Instance Method Details

#[](key) ⇒ Object

Returns the value of the stat titled key (if any)



54
55
56
# File 'lib/dakwak/analytics/sheet.rb', line 54

def [](key)
  @content[key]
end

#[]=(key, value) ⇒ Object

Defines a new stat as key with any kind of value in value



59
60
61
# File 'lib/dakwak/analytics/sheet.rb', line 59

def []=(key, value)
  @content[key] = value
end

#commit!Object

Submits the sheet to the analytics platform.



64
65
66
67
# File 'lib/dakwak/analytics/sheet.rb', line 64

def commit!
  Dakwak.logger.log_debug "Comitting dakana sheet: #{serialize}" if Dakwak.debugging?
  Communicator.new.publish(Message.new(serialize, {}), "analytics", Dakwak.app_name)
end