Class: Page
- Inherits:
-
Object
- Object
- Page
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#visitors ⇒ Object
readonly
Returns the value of attribute visitors.
Instance Method Summary collapse
- #<<(visitor) ⇒ Object
-
#initialize(path:, visitors: []) ⇒ Page
constructor
A new instance of Page.
- #to_s(strategy: DEFAULT_PAGE_PRESENTATION_STRATEGY) ⇒ Object
- #unique_view_count ⇒ Object
- #view_count ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/page.rb', line 6 def path @path end |
#visitors ⇒ Object (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_count ⇒ Object
21 22 23 |
# File 'lib/page.rb', line 21 def unique_view_count visitors.uniq.count end |
#view_count ⇒ Object
17 18 19 |
# File 'lib/page.rb', line 17 def view_count visitors.count end |