Sha256: 4c9e55df839b61aaaa833cdc72366cc64bf97c429e1147cc9ff4a32a3436a919

Contents?: true

Size: 499 Bytes

Versions: 2

Compression:

Stored size: 499 Bytes

Contents

module Cohortly
  class PeriodCohort < Cohortly::UserCohort
    key :start_time, Time
    key :weekly, Boolean

    def end_time
      self.start_time + period
    end

    def period
      self.weekly ? 1.week : 1.month
    end

    def key_pattern
      self.weekly ? "%Y-%W" : "%Y-%m"
    end

    def store!
      self.user_ids = Cohortly::Cohorts.range(self.start_time..self.end_time)
      self.name = (self.start_time + 3.days).strftime(key_pattern)
      self.save        
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cohortly-0.0.93 app/models/cohortly/period_cohort.rb
cohortly-0.0.92 app/models/cohortly/period_cohort.rb