Class: AustinCrime::Crime
- Inherits:
-
Object
- Object
- AustinCrime::Crime
- Defined in:
- lib/austin_crime/crime.rb
Overview
this is the core of my scraper - json lives here
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Crime
constructor
A new instance of Crime.
Constructor Details
#initialize ⇒ Crime
Returns a new instance of Crime.
5 6 7 |
# File 'lib/austin_crime/crime.rb', line 5 def initialize @response = response end |
Class Method Details
.cruelty ⇒ Object
23 24 25 26 |
# File 'lib/austin_crime/crime.rb', line 23 def self.cruelty @response = HTTParty.get(url + "'CRUELTY TO ANIMALS')&$limit=10") yeesh end |
.dwi ⇒ Object
13 14 15 16 |
# File 'lib/austin_crime/crime.rb', line 13 def self.dwi @response = HTTParty.get(url + "'DWI')&$limit=10") yeesh end |
.harassment ⇒ Object
18 19 20 21 |
# File 'lib/austin_crime/crime.rb', line 18 def self.harassment @response = HTTParty.get(url + "'HARASSMENT')&$limit=10") yeesh end |
.theft ⇒ Object
28 29 30 31 |
# File 'lib/austin_crime/crime.rb', line 28 def self.theft @response = HTTParty.get(url + "'THEFT')&$limit=10") yeesh end |
.url ⇒ Object
9 10 11 |
# File 'lib/austin_crime/crime.rb', line 9 def self.url url = 'https://data.austintexas.gov/resource/rkrg-9tez.json?$where=starts_with(crime_type,' end |
.yeesh ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/austin_crime/crime.rb', line 33 def self.yeesh puts "Got #{@response.count} results. Showing first result:" @response.first.each do |k, v| puts "#{k}: #{v}" end puts "\nEnter 'more' if you'd like to browse more entries or 'q' if you'd like Quit" input = gets.chomp if input == 'more' @response.collect do |hash| puts '--------------------' hash.collect do |k, v| # not supposed to use collect on hashes? puts "#{k}: #{v}" end.compact.reject(&:empty?) # c_cole on the assist end elsif input == 'q' puts "But you just got here! Thanks for viewing." abort else puts 'Not sure what you want. Please try again.' end end |