Class: Octo::Funnel
- Inherits:
-
Object
- Object
- Octo::Funnel
- Includes:
- Cequel::Record, Record
- Defined in:
- lib/octocore-cassandra/models/enterprise/funnels.rb
Overview
Stores the funnel for the enterprise
Constant Summary
Constants included from Cequel::Record
Class Method Summary collapse
-
.from_pages(pages, opts = {}) ⇒ Octo::Funnel
Generates a new funnel from the pages provided.
Instance Method Summary collapse
-
#activate_funnel ⇒ Object
Activates a funnel.
-
#create_name_slug ⇒ Object
Creates name slug.
-
#data(ts = Time.now.floor) ⇒ Octo::FunnelData
Returns data for a funnel.
-
#populate_with_fake_data(interval_days = 7) ⇒ Object
Populates a newly created funnel with some fake data.
Methods included from Record
Methods included from Cequel::Record
#marshal_dump, #marshal_load, redis, update_cache_config
Class Method Details
.from_pages(pages, opts = {}) ⇒ Octo::Funnel
Generates a new funnel from the pages provided
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/octocore-cassandra/models/enterprise/funnels.rb', line 50 def self.from_pages(pages, opts = {}) funnel_length = pages.count return nil if funnel_length.zero? funnel = Array.new enterprise_id = opts.fetch(:enterprise_id, nil) # Check if they are Octo::Product or Octo::Page instantces and handle if ::Set.new([Octo::Product, Octo::Page]).include?(pages[0].class) funnel = pages.collect { |p| p.routeurl } enterprise_id = pages[0].enterprise_id elsif pages[0].class == String funnel = pages end # Create a new funnel self.new( enterprise_id: enterprise_id, name: opts.fetch(:name), funnel: funnel ).save! end |
Instance Method Details
#activate_funnel ⇒ Object
Activates a funnel
35 36 37 |
# File 'lib/octocore-cassandra/models/enterprise/funnels.rb', line 35 def activate_funnel self.active = true end |
#create_name_slug ⇒ Object
Creates name slug
30 31 32 |
# File 'lib/octocore-cassandra/models/enterprise/funnels.rb', line 30 def create_name_slug self.name_slug = self.name.to_slug end |
#data(ts = Time.now.floor) ⇒ Octo::FunnelData
Returns data for a funnel
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/octocore-cassandra/models/enterprise/funnels.rb', line 91 def data(ts = Time.now.floor) args = { enterprise_id: self.enterprise.id, funnel_slug: self.name_slug, ts: ts } res = Octo::FunnelData.where(args) if res.count > 0 res.first elsif self.enterprise.fakedata? args.merge!({ value: fake_data(self.funnel.count) }) Octo::FunnelData.new(args).save! end end |
#populate_with_fake_data(interval_days = 7) ⇒ Object
Populates a newly created funnel with some fake data
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/octocore-cassandra/models/enterprise/funnels.rb', line 75 def populate_with_fake_data(interval_days = 7) if self.enterprise.fakedata? today = Time.now.beginning_of_day (today - interval_days.days).to(today, 24.hour).each do |ts| Octo::FunnelData.new( enterprise_id: self.enterprise_id, funnel_slug: self.name_slug, ts: ts, value: fake_data(self.funnel.count) ).save! end end end |