class Octo::Segment
The segment class. Responsible for segments
Public Class Methods
find_by_enterprise_and_name(enterprise, name)
click to toggle source
# File lib/octocore-mongo/models/enterprise/segment.rb, line 58 def self.find_by_enterprise_and_name(enterprise, name) where({enterprise_id: enterprise._id, name_slug: name.to_slug}) end
Public Instance Methods
activate()
click to toggle source
# File lib/octocore-mongo/models/enterprise/segment.rb, line 37 def activate self.active = true end
create_name_slug()
click to toggle source
Creates name slug
# File lib/octocore-mongo/models/enterprise/segment.rb, line 33 def create_name_slug self.name_slug = self.name.to_slug end
data(ts = Time.now.floor)
click to toggle source
# File lib/octocore-mongo/models/enterprise/segment.rb, line 41 def data(ts = Time.now.floor) args = { enterprise_id: self.enterprise._id, segment_slug: self.name_slug, ts: ts } res = Octo::SegmentData.where(args) if res.count > 0 res.first elsif self.enterprise.fakedata? # populate a poser data val = [rand(1000..10000), rand(0.0..70.0)] args.merge!({ value: val }) Octo::SegmentData.new(args).save! end end