Class: Hyrax::Statistics::Works::Count

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/statistics/works/count.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date = nil, end_date = nil) ⇒ Count

Returns a new instance of Count.

Parameters:

  • start_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to after this date. nil means no filter

  • end_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to before this date. nil means today



21
22
23
24
# File 'app/services/hyrax/statistics/works/count.rb', line 21

def initialize(start_date = nil, end_date = nil)
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



6
7
8
# File 'app/services/hyrax/statistics/works/count.rb', line 6

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



6
7
8
# File 'app/services/hyrax/statistics/works/count.rb', line 6

def start_date
  @start_date
end

Class Method Details

.by_permission(start_date: nil, end_date: nil) ⇒ Hash

Retrieves the count of works in the system filtered by the start_date and end_date if present

Parameters:

  • start_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to after this date. nil means no filter

  • end_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to before this date. nil means today

Returns:

  • (Hash)

    A hash with the total files by permission for the system

See Also:



15
16
17
# File 'app/services/hyrax/statistics/works/count.rb', line 15

def self.by_permission(start_date: nil, end_date: nil)
  new(start_date, end_date).by_permission
end

Instance Method Details

#by_permissionHash

Retrieves the count of works in the system filtered by the start_date and end_date if present

Parameters:

  • [Number] (Hash)

    a customizable set of options

Returns:

  • (Hash)

    A hash with the total files by permission for the system



33
34
35
36
37
38
39
40
41
42
# File 'app/services/hyrax/statistics/works/count.rb', line 33

def by_permission
  return by_date_and_permission if start_date

  works_count = {}
  works_count[:total] = query_service.count
  works_count[:public] = query_service.where_public.count
  works_count[:registered] = query_service.where_registered.count
  works_count[:private] = works_count[:total] - (works_count[:registered] + works_count[:public])
  works_count
end