Class: Kameleoon::DataManager::PageViewVisit

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/data/manager/page_view_visit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_view, count = 1, timestamp = nil) ⇒ PageViewVisit

Returns a new instance of PageViewVisit.



12
13
14
15
16
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 12

def initialize(page_view, count = 1, timestamp = nil)
  @page_view = page_view
  @count = count
  @last_timestamp = timestamp.nil? ? Time.new.to_i : timestamp
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



6
7
8
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 6

def count
  @count
end

#last_timestampObject (readonly)

Returns the value of attribute last_timestamp.



6
7
8
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 6

def last_timestamp
  @last_timestamp
end

#page_viewObject (readonly)

Returns the value of attribute page_view.



6
7
8
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 6

def page_view
  @page_view
end

Instance Method Details

#increase_page_visitsObject

Not thread-save method, should be called in synchronized code



33
34
35
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 33

def increase_page_visits
  @count += 1
end

#merge(page_view_visit) ⇒ Object

Not thread-save method, should be called in synchronized code



27
28
29
30
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 27

def merge(page_view_visit)
  @count += page_view_visit.count
  @last_timestamp = [@last_timestamp, page_view_visit.last_timestamp].max
end

#overwrite(page_view) ⇒ Object

Not thread-save method, should be called in synchronized code We need to return a new PageViewVisit for case if PageView was already sent and it’s new visit



20
21
22
23
24
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 20

def overwrite(page_view)
  @page_view = page_view
  @count += 1
  @last_timestamp = Time.new.to_i
end

#to_sObject



8
9
10
# File 'lib/kameleoon/data/manager/page_view_visit.rb', line 8

def to_s
  "PageViewVisit{last_timestamp:#{@last_timestamp},count:#{@count},page_view:#{@page_view}}"
end