Class: CrimeCrimeChicago::Crime

Inherits:
Object
  • Object
show all
Defined in:
lib/crime_crime_chicago.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Crime

Returns a new instance of Crime.



8
9
10
11
12
13
14
# File 'lib/crime_crime_chicago.rb', line 8

def initialize(hash)
  @id = hash["id"]
  @date = hash["date"]
  @primary_type = hash["primary_type"]
  @description = hash["description"]
  @arrest = hash["arrest"]
end

Instance Attribute Details

#arrestObject (readonly)

Returns the value of attribute arrest.



6
7
8
# File 'lib/crime_crime_chicago.rb', line 6

def arrest
  @arrest
end

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/crime_crime_chicago.rb', line 6

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/crime_crime_chicago.rb', line 6

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/crime_crime_chicago.rb', line 6

def id
  @id
end

#primary_typeObject (readonly)

Returns the value of attribute primary_type.



6
7
8
# File 'lib/crime_crime_chicago.rb', line 6

def primary_type
  @primary_type
end

Class Method Details

.allObject



16
17
18
19
20
21
22
# File 'lib/crime_crime_chicago.rb', line 16

def self.all 
  collection = []
  Unirest.get('https://data.cityofchicago.org/resource/vwwp-7yr9.json').body.each do |crime_hash|
    collection << Crime.new(crime_hash)
  end
  collection
end

.find(params_id) ⇒ Object



24
25
26
# File 'lib/crime_crime_chicago.rb', line 24

def self.find(params_id)
  Crime.new(Unirest.get("https://data.cityofchicago.org/resource/vwwp-7yr9.json?id=#{params_id}").body.first)
end