Class: WorkUsage
- Inherits:
-
Object
- Object
- WorkUsage
- Defined in:
- app/presenters/work_usage.rb
Overview
class WorkUsage follows the model established by FileUsage Called by the stats controller, it finds cached work pageview data, and prepares it for visualization in /app/views/stats/work.html.erb
Instance Attribute Summary collapse
-
#created ⇒ Object
Returns the value of attribute created.
-
#id ⇒ Object
Returns the value of attribute id.
-
#pageviews ⇒ Object
Returns the value of attribute pageviews.
-
#work ⇒ Object
Returns the value of attribute work.
Instance Method Summary collapse
-
#initialize(id) ⇒ WorkUsage
constructor
A new instance of WorkUsage.
-
#to_flot ⇒ Object
Package data for visualization using JQuery Flot.
- #total_pageviews ⇒ Object
Constructor Details
#initialize(id) ⇒ WorkUsage
Returns a new instance of WorkUsage.
8 9 10 11 12 13 14 15 16 |
# File 'app/presenters/work_usage.rb', line 8 def initialize(id) @work = CurationConcerns::WorkRelation.new.find(id) user = User.find_by(email: work.depositor) user_id = user ? user.id : nil self.id = id self.created = date_for_analytics(work) self.pageviews = WorkViewStat.to_flots WorkViewStat.statistics(work, created, user_id) end |
Instance Attribute Details
#created ⇒ Object
Returns the value of attribute created.
6 7 8 |
# File 'app/presenters/work_usage.rb', line 6 def created @created end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'app/presenters/work_usage.rb', line 6 def id @id end |
#pageviews ⇒ Object
Returns the value of attribute pageviews.
6 7 8 |
# File 'app/presenters/work_usage.rb', line 6 def pageviews @pageviews end |
#work ⇒ Object
Returns the value of attribute work.
6 7 8 |
# File 'app/presenters/work_usage.rb', line 6 def work @work end |
Instance Method Details
#to_flot ⇒ Object
Package data for visualization using JQuery Flot
25 26 27 28 29 |
# File 'app/presenters/work_usage.rb', line 25 def to_flot [ { label: "Pageviews", data: pageviews } ] end |
#total_pageviews ⇒ Object
20 21 22 |
# File 'app/presenters/work_usage.rb', line 20 def total_pageviews pageviews.reduce(0) { |total, result| total + result[1].to_i } end |