Module: Bluecap::Keys

Defined in:
lib/bluecap/keys.rb

Class Method Summary collapse

Class Method Details

.clean(str) ⇒ Object

Returns a cleaned version of a string for use in a Redis key. Strips, downcases, then treats any remaining characters like word separators as periods.

str - The String to be cleaned.

Examples

clean('Country')
# => "country"

clean('Logged In')
# => "logged.in"

Returns the new String.



19
20
21
# File 'lib/bluecap/keys.rb', line 19

def self.clean(str)
  str.strip.downcase.gsub(/[^a-z0-9]/, '.')
end

.cohort(report_id, cohort_id) ⇒ Object



35
36
37
# File 'lib/bluecap/keys.rb', line 35

def self.cohort(report_id, cohort_id)
  "reports:cohort:#{report_id}:#{cohort_id}"
end

.engagement(report_id, cohort_id, date) ⇒ Object



39
40
41
# File 'lib/bluecap/keys.rb', line 39

def self.engagement(report_id, cohort_id, date)
  "reports:e:#{report_id}:#{cohort_id}:#{date}"
end

.event(name, date) ⇒ Object

Returns a key used to store the events for a day.

Examples

Bluecap::Keys.event 'Sign Up', '20120710'
# => "events:sign.up:20120710"

Returns the String key.



31
32
33
# File 'lib/bluecap/keys.rb', line 31

def self.event(name, date)
  "events:#{clean(name)}:#{date}"
end