class Garden
Attributes
borough[R]
gardenname[R]
multipolygon[R]
parksid[R]
status[R]
zipcode[R]
Public Class Methods
all()
click to toggle source
# File lib/garden.rb, line 19 def self.all @@all end
filter_by_borough(borough)
click to toggle source
# File lib/garden.rb, line 39 def self.filter_by_borough(borough) if borough == "all" @@all else @@all.select {|g| g.borough == borough} end #select creates a new array with all gardens (object IDs) that match it end
filter_by_status(status)
click to toggle source
# File lib/garden.rb, line 53 def self.filter_by_status(status) @@all.select {|g| g.status == status} end
filter_by_zip(zipcode)
click to toggle source
# File lib/garden.rb, line 49 def self.filter_by_zip(zipcode) @@all.select {|g| g.zipcode == zipcode} end
new(borough, gardenname, multipolygon, parksid, status, zipcode)
click to toggle source
# File lib/garden.rb, line 9 def initialize (borough, gardenname, multipolygon, parksid, status, zipcode) @borough = borough @gardenname = gardenname @multipolygon = multipolygon @parksid = parksid @status = status @zipcode = zipcode @@all << self end
print_top_zipcodes(borough)
click to toggle source
# File lib/garden.rb, line 68 def self.print_top_zipcodes(borough) highest_sorted_zipcodes = self.zipcode_hash(borough).sort_by{|k,v| v}.reverse highest_sorted_zipcodes.first(5).map {|k,v| puts "#{"#{v}".magenta} gardens in #{"#{k}".yellow}".indent(4)} end
translate_borough(borough)
click to toggle source
# File lib/garden.rb, line 24 def self.translate_borough(borough) if borough == "B" "Brooklyn" elsif borough == "X" "the Bronx" elsif borough == "M" "Manhattan" elsif borough == "Q" "Queens" elsif borough == "R" "Staten Island" end end
zipcode_hash(borough)
click to toggle source
# File lib/garden.rb, line 58 def self.zipcode_hash(borough) zipcode_count = {} self.filter_by_borough(borough).map do |g| zipcode_count[g.zipcode] = self.filter_by_zip(g.zipcode).count end zipcode_count end