app/presenters/hyrax/admin_stats_presenter.rb in hyrax-2.1.0 vs app/presenters/hyrax/admin_stats_presenter.rb in hyrax-2.2.0
- old
+ new
@@ -1,13 +1,52 @@
module Hyrax
class AdminStatsPresenter
attr_reader :limit, :stats_filters
- def initialize(stats_filters, limit)
+ ##
+ # @!attribute [rw] by_depositor
+ # @return [#query]
+ # @!attribute [rw] by_format
+ # @return [#query]
+ # @!attribute [rw] depositor_summary
+ # @return [#depositors]
+ # @!attribute [rw] system_stats
+ # @return [#recent_users]
+ # @!attribute [rw] works_counter
+ # @return [#by_permission]
+ attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
+ :works_counter
+
+ # Long parameter lists (especially optional) are preferred to hard-coded
+ # dependencies. Further refactors may be desirable.
+ #
+ # rubocop:disable Metrics/ParameterLists
+
+ ##
+ # @param stats_filters [Hash<Symbol, Object>]
+ # @param limit [FixNum]
+ # @param by_depositor [#query]
+ # @param by_format [#query]
+ # @param depositor_summary [#depositors]
+ # @param system_stats [#recent_users]
+ # @param works_counter [#by_permission]
+ def initialize(stats_filters, limit,
+ by_depositor: Hyrax::Statistics::Works::ByDepositor,
+ by_format: Hyrax::Statistics::FileSets::ByFormat,
+ depositor_summary: Hyrax::Statistics::Depositors::Summary,
+ system_stats: Hyrax::Statistics::SystemStats,
+ works_counter: Hyrax::Statistics::Works::Count)
@stats_filters = stats_filters
@limit = limit
+
+ self.by_depositor = by_depositor
+ self.by_format = by_format
+ self.depositor_summary = depositor_summary
+ self.system_stats = system_stats
+ self.works_counter = works_counter
end
+ # rubocop:enable Metrics/ParameterLists
def start_date
@start_date ||= extract_date_from_stats_filters(key: :start_date, as_of: :beginning_of_day)
end
@@ -24,32 +63,39 @@
public
# @see Hyrax::Statistics::Depositors::Summary
def depositors
- @depositors ||= Hyrax::Statistics::Depositors::Summary.depositors(start_date: start_date, end_date: end_date)
+ @depositors ||=
+ depositor_summary.depositors(start_date: start_date, end_date: end_date)
end
# @see Hyrax::Statistics::SystemStats.recent_users
def recent_users
- @recent_users ||= Hyrax::Statistics::SystemStats.recent_users(limit: limit, start_date: start_date, end_date: end_date)
+ @recent_users ||=
+ system_stats.recent_users(limit: limit,
+ start_date: start_date,
+ end_date: end_date)
end
# @see Hyrax::Statistics::Works::ByDepositor
def active_users
- @active_users ||= Hyrax::Statistics::Works::ByDepositor.query(limit: limit)
+ @active_users ||= by_depositor.query(limit: limit)
end
# @see Hyrax::Statistics::FileSets::ByFormat
def top_formats
- @top_formats ||= Hyrax::Statistics::FileSets::ByFormat.query(limit: limit)
+ @top_formats ||= by_format.query(limit: limit)
end
# @see Hyrax::Statistics::Works::Count
def works_count
- @works_count ||= Hyrax::Statistics::Works::Count.by_permission(start_date: start_date, end_date: end_date)
+ @works_count ||=
+ works_counter.by_permission(start_date: start_date, end_date: end_date)
end
+ ##
+ # @return [String]
def date_filter_string
if start_date.blank?
"unfiltered"
elsif end_date.blank?
"#{start_date.to_date.to_formatted_s(:standard)} to #{Date.current.to_formatted_s(:standard)}"