Class: ESP::StatRegion

Inherits:
Resource
  • Object
show all
Includes:
StatTotals
Defined in:
lib/esp/resources/stat_region.rb

Class Method Summary collapse

Methods included from StatTotals

#destroy, #save, #total, #total_suppressed

Methods inherited from Resource

arrange_options, filters, make_pageable, #serializable_hash, where

Class Method Details

.find(*arguments) ⇒ Object

Find a StatRegion by id

Parameter

id | Required | The ID of the region stat to retrieve

:call-seq:

find(id)


31
32
33
34
35
36
37
38
# File 'lib/esp/resources/stat_region.rb', line 31

def self.find(*arguments)
  scope = arguments.slice!(0)
  options = (arguments.slice!(0) || {}).with_indifferent_access
  return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
  params = options.fetch(:params, {}).with_indifferent_access
  stat_id = params.delete(:stat_id)
  for_stat(stat_id)
end

.for_stat(stat_id = nil) ⇒ Object

Returns a paginated collection of region stats for the given stat_id Convenience method to use instead of ::find since a stat_id is required to return region stats.

Parameter

stat_id | Required | The ID of the stat to list region stats for

Example

stats = ESP::StatRegion.for_stat(1194)


17
18
19
20
21
# File 'lib/esp/resources/stat_region.rb', line 17

def self.for_stat(stat_id = nil)
  fail ArgumentError, "You must supply a stat id." unless stat_id.present?
  from = "#{prefix}stats/#{stat_id}/regions.json"
  find(:all, from: from)
end