Module: MassShootings::Tracker

Defined in:
lib/mass_shootings/tracker.rb

Overview

Retrieves mass shootings from the [r/GunsAreCool shooting tracker] (www.reddit.com/r/GunsAreCool/wiki/2015massshootings).

Class Method Summary collapse

Class Method Details

.get(id) ⇒ Object

Retrieves a ‘Shooting` by unique ID.

Parameters:

  • id (String)

    the ‘Shooting`’s unique identifier. This is opaque; you should not depend on its format.



18
19
20
21
# File 'lib/mass_shootings/tracker.rb', line 18

def get(id)
  year, number = id.split '-', 2
  page(year)[id]
end

.in_date_range(date_range) ⇒ Object

Retrieves all ‘Shooting`s that occurred within a date range.

Parameters:

  • date_range (Range<Date>)

    the date range to search. Inclusive and exclusive ranges are both supported.



28
29
30
31
32
33
# File 'lib/mass_shootings/tracker.rb', line 28

def in_date_range(date_range)
  pages_in_date_range(date_range).
    map(&method(:page)).
    flat_map(&:to_a).
    select { |shooting| date_range.cover? shooting.date }
end

.resetObject

Invalidates the in-memory cache. In a long-running process, you should arrange for this method to be called approximately every 24 hours and 36 minutes.



40
41
42
# File 'lib/mass_shootings/tracker.rb', line 40

def reset
  @pages = {}
end