Class: Analytic::Dashboard
- Inherits:
-
Object
- Object
- Analytic::Dashboard
- Defined in:
- app/models/analytic/dashboard.rb
Constant Summary collapse
- PAGES_LIMIT =
8
Instance Attribute Summary collapse
- #period ⇒ String readonly
Instance Method Summary collapse
- #current ⇒ Period
- #duration ⇒ Interval
-
#initialize(period:) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #name ⇒ String
- #prior ⇒ Period
- #range ⇒ Range<Time>
- #range? ⇒ Boolean
- #sessions ⇒ Stat
- #views ⇒ Stat
- #visitors ⇒ Stat
Constructor Details
#initialize(period:) ⇒ Dashboard
Returns a new instance of Dashboard.
11 12 13 |
# File 'app/models/analytic/dashboard.rb', line 11 def initialize(period:) @period = period end |
Instance Attribute Details
#period ⇒ String (readonly)
8 9 10 |
# File 'app/models/analytic/dashboard.rb', line 8 def period @period end |
Instance Method Details
#current ⇒ Period
52 53 54 |
# File 'app/models/analytic/dashboard.rb', line 52 def current @current ||= Period.new(range:) end |
#duration ⇒ Interval
75 76 77 78 79 80 81 82 83 |
# File 'app/models/analytic/dashboard.rb', line 75 def duration @duration ||= case @period when '24h' then 24.hours when '7d' then 7.days when '4w' then 4.weeks when '12m' then 12.months end end |
#name ⇒ String
43 44 45 46 47 48 49 |
# File 'app/models/analytic/dashboard.rb', line 43 def name if @period "#{@period.capitalize} | Dashboard" else 'Dashboard' end end |
#prior ⇒ Period
57 58 59 60 61 62 |
# File 'app/models/analytic/dashboard.rb', line 57 def prior return unless range? return @prior if defined?(@prior) @prior ||= Period.new(range: ((range.min - duration)..(range.max - duration))) end |
#range ⇒ Range<Time>
70 71 72 |
# File 'app/models/analytic/dashboard.rb', line 70 def range (now - duration)..now if range? end |
#range? ⇒ Boolean
65 66 67 |
# File 'app/models/analytic/dashboard.rb', line 65 def range? @period.present? end |
#sessions ⇒ Stat
34 35 36 37 38 39 40 |
# File 'app/models/analytic/dashboard.rb', line 34 def sessions Stat.new( current: current.distinct_sessions_count, prior: prior&.distinct_sessions_count, name: 'Sessions' ) end |