Class: Page

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

Overview

Represents a record of a page that can be visited, holding a record of the visitors via their ip address

Constant Summary collapse

DEFAULT_PAGE_PRESENTATION_STRATEGY =
proc do |page|
  "#{page.path} visited by #{page.visitors.uniq}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, visitors: []) ⇒ Page

Returns a new instance of Page.



8
9
10
11
# File 'lib/page.rb', line 8

def initialize(path:, visitors: [])
  @path = path
  @visitors = visitors
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/page.rb', line 6

def path
  @path
end

#visitorsObject (readonly)

Returns the value of attribute visitors.



6
7
8
# File 'lib/page.rb', line 6

def visitors
  @visitors
end

Instance Method Details

#<<(visitor) ⇒ Object



13
14
15
# File 'lib/page.rb', line 13

def <<(visitor)
  visitors << visitor
end

#to_s(strategy: DEFAULT_PAGE_PRESENTATION_STRATEGY) ⇒ Object



25
26
27
# File 'lib/page.rb', line 25

def to_s(strategy: DEFAULT_PAGE_PRESENTATION_STRATEGY)
  strategy.call(self)
end

#unique_view_countObject



21
22
23
# File 'lib/page.rb', line 21

def unique_view_count
  visitors.uniq.count
end

#view_countObject



17
18
19
# File 'lib/page.rb', line 17

def view_count
  visitors.count
end