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
-
.get(id) ⇒ Object
Retrieves a ‘Shooting` by unique ID.
-
.in_date_range(date_range) ⇒ Object
Retrieves all ‘Shooting`s that occurred within a date range.
-
.reset ⇒ Object
Invalidates the in-memory cache.
Class Method Details
.get(id) ⇒ Object
Retrieves a ‘Shooting` by unique ID.
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.
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 |
.reset ⇒ Object
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 |