Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/crunchr/active_record.rb

Instance Method Summary collapse

Instance Method Details

#interval_fmt(length) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/crunchr/active_record.rb', line 46

def interval_fmt(length)
  case length
  when :hour
    "%Y%j%H"
  when :day
    "%Y%j"
  when :week
    "%Y%W"
  when :month
    "%Y%m"
  when :year
    "%Y"
  else
    raise "Invalid interval length: #{length}"
  end
end

#interval_time(length) ⇒ Object



42
43
44
# File 'lib/crunchr/active_record.rb', line 42

def interval_time(length)
  self.created_at.strftime(interval_fmt(length)).to_i
end