Class: Kameleoon::DataManager::PageViewVisit
- Inherits:
-
Object
- Object
- Kameleoon::DataManager::PageViewVisit
- Defined in:
- lib/kameleoon/data/manager/page_view_visit.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#last_timestamp ⇒ Object
readonly
Returns the value of attribute last_timestamp.
-
#page_view ⇒ Object
readonly
Returns the value of attribute page_view.
Instance Method Summary collapse
-
#increase_page_visits ⇒ Object
Not thread-save method, should be called in synchronized code.
-
#initialize(page_view, count = 1, timestamp = nil) ⇒ PageViewVisit
constructor
A new instance of PageViewVisit.
-
#merge(page_view_visit) ⇒ Object
Not thread-save method, should be called in synchronized code.
-
#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.
- #to_s ⇒ Object
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, = nil) @page_view = page_view @count = count @last_timestamp = .nil? ? Time.new.to_i : end |
Instance Attribute Details
#count ⇒ Object (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_timestamp ⇒ Object (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 end |
#page_view ⇒ Object (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_visits ⇒ Object
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.].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_s ⇒ Object
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 |